1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-11-01 19:07:38 +01:00
unleash.unleash/src/lib/util/validateJsonString.test.ts

23 lines
801 B
TypeScript
Raw Normal View History

import { validateJsonString } from './validateJsonString';
test('should return true for valid json string', () => {
const input = '{"test":1,"nested":[{"test1":{"testinner":true}}]}';
expect(validateJsonString(input)).toBe(true);
});
test('should return false for invalid json string (missing starting {)', () => {
// missing starting {
const input = '"test":1,"nested":[{"test1":{"testinner":true}}]}';
expect(validateJsonString(input)).toBe(false);
});
test('should return false for invalid json string (plain string)', () => {
const input = 'not a json';
expect(validateJsonString(input)).toBe(false);
});
test('should return false for invalid json string (null as a string)', () => {
const input = 'null';
expect(validateJsonString(input)).toBe(false);
});