Files
common/packages/util/src/is/jsonObject.spec.ts
T
Jaco 3e2c3a6ed8 Move test cryptoWaitReady top-level (#1747)
* Move test cryptoWaitReady top-level

* Add missing mod.ts

* Revert mod.ts add

* Add types reference for tests

* Adjust

* adjust

* node:fs & node:path
2023-02-25 11:13:51 +02:00

53 lines
1.1 KiB
TypeScript

// Copyright 2017-2023 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
// eslint-disable-next-line spaced-comment
/// <reference types="@polkadot/dev/node/test/node" />
import { isJsonObject } from '.';
const jsonObject = `{
"Test": "1234",
"NestedTest": {
"Test": "5678"
}
}`;
describe('isJsonObject', (): void => {
it('returns true on empty objects', (): void => {
expect(
isJsonObject({})
).toEqual(true);
});
it('returns true on JSON objects', (): void => {
expect(
isJsonObject(jsonObject)
).toEqual(true);
});
it('returns false on JSON parsable value typeof number', (): void => {
expect(
isJsonObject(1234)
).toEqual(false);
});
it('returns false on JSON parsable value null', (): void => {
expect(
isJsonObject(null)
).toEqual(false);
});
it('returns false on invalid objects', (): void => {
expect(
isJsonObject('notAnObject')
).toEqual(false);
});
it('returns false on invalid JSON', (): void => {
expect(
isJsonObject('{"abc", "def"}')
).toEqual(false);
});
});