yupExtended.spec.ts 702 B

123456789101112131415161718192021222324
  1. import { isValidJsonObject } from 'lib/yupExtended';
  2. describe('yup extended', () => {
  3. describe('isValidJsonObject', () => {
  4. it('returns false for no value', () => {
  5. expect(isValidJsonObject()).toBeFalsy();
  6. });
  7. it('returns false for invalid string', () => {
  8. expect(isValidJsonObject('foo: bar')).toBeFalsy();
  9. });
  10. it('returns false on parsing error', () => {
  11. JSON.parse = jest.fn().mockImplementationOnce(() => {
  12. throw new Error();
  13. });
  14. expect(isValidJsonObject('{ "foo": "bar" }')).toBeFalsy();
  15. });
  16. it('returns true for valid JSON object', () => {
  17. expect(isValidJsonObject('{ "foo": "bar" }')).toBeTruthy();
  18. });
  19. });
  20. });