apphouse
Version:
Component library for React that uses observable state management and theme-able components.
31 lines (25 loc) • 979 B
text/typescript
import { validateJSON } from './validateJson';
describe('validateJSON function', () => {
it('should return true for valid JSON', () => {
const jsonString = '{"name": "John", "age": 30}';
expect(validateJSON(jsonString)).toBe(true);
});
it('should return false for invalid JSON', () => {
const invalidJSONString = '{"name": "John", age: 30}';
expect(validateJSON(invalidJSONString)).toBe(false);
});
it('should return false for non-string input', () => {
const nonStringInput = 123;
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
expect(validateJSON(nonStringInput)).toBe(false);
});
it('should return false for empty string', () => {
const emptyString = '';
expect(validateJSON(emptyString)).toBe(false);
});
it('should return false for non-JSON string', () => {
const nonJSONString = 'This is not a valid JSON string';
expect(validateJSON(nonJSONString)).toBe(false);
});
});