Files
common/packages/util/src/is/jsonObject.spec.ts
T
2020-09-17 16:13:39 +02:00

50 lines
1.0 KiB
TypeScript

// Copyright 2017-2020 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
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);
});
});