diff --git a/src/test/utils/isValidJson.spec.ts b/src/test/utils/isValidJson.spec.ts new file mode 100644 index 0000000..bd5a970 --- /dev/null +++ b/src/test/utils/isValidJson.spec.ts @@ -0,0 +1,31 @@ +import { isValidJson } from "../../utils" + +describe.only('jsonValidator', () => { + it('should not throw an error with an valid json', () => { + const json = { + test: 'test' + } + + expect(isValidJson(json)).not.toThrowError + }) + + it('should not throw an error with an valid json string', () => { + const json = JSON.stringify({ + test: 'test' + }) + + expect(isValidJson(json)).not.toThrowError + }) + + it('should throw an error with an invalid json', () => { + const json = `{\"test\":\"test\"\"test2\":\"test\"}` + + expect(() => { + try { + isValidJson(json) + } catch(err) { + throw new Error() + } + }).toThrowError + }) +}) \ No newline at end of file