From b590a9f41b44ec48c02dce0a34a94ac125a29a73 Mon Sep 17 00:00:00 2001 From: Mihajlo Date: Mon, 12 Jul 2021 12:58:04 +0200 Subject: [PATCH] chore(tests): testing the isValidJson function --- src/test/utils/isValidJson.spec.ts | 31 ++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/test/utils/isValidJson.spec.ts 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