Added test spec for helpers/jsonParse.js
This commit is contained in:
parent
e31979002f
commit
73dc0b1cfa
1 changed files with 34 additions and 0 deletions
34
helpers/__tests__/jsonParse.spec.js
Normal file
34
helpers/__tests__/jsonParse.spec.js
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import jsonParse from "../jsonParse"
|
||||
|
||||
describe("jsonParse", () => {
|
||||
test("parses without errors for valid JSON", () => {
|
||||
const testJSON = JSON.stringify({
|
||||
name: "hoppscotch",
|
||||
url: "https://hoppscotch.io",
|
||||
awesome: true,
|
||||
when: 2019,
|
||||
})
|
||||
|
||||
expect(() => jsonParse(testJSON)).not.toThrow()
|
||||
})
|
||||
|
||||
test("throws error for invalid JSON", () => {
|
||||
const testJSON = '{ "name": hopp "url": true }'
|
||||
|
||||
expect(() => jsonParse(testJSON)).toThrow()
|
||||
})
|
||||
|
||||
test("thrown error has proper info fields", () => {
|
||||
expect.assertions(3)
|
||||
|
||||
const testJSON = '{ "name": hopp "url": true }'
|
||||
|
||||
try {
|
||||
jsonParse(testJSON)
|
||||
} catch (e) {
|
||||
expect(e).toHaveProperty("start")
|
||||
expect(e).toHaveProperty("end")
|
||||
expect(e).toHaveProperty("message")
|
||||
}
|
||||
})
|
||||
})
|
||||
Loading…
Reference in a new issue