jsonParse.spec.js 804 B

12345678910111213141516171819202122232425262728293031323334
  1. import jsonParse from "../jsonParse"
  2. describe("jsonParse", () => {
  3. test("parses without errors for valid JSON", () => {
  4. const testJSON = JSON.stringify({
  5. name: "hoppscotch",
  6. url: "https://hoppscotch.io",
  7. awesome: true,
  8. when: 2019,
  9. })
  10. expect(() => jsonParse(testJSON)).not.toThrow()
  11. })
  12. test("throws error for invalid JSON", () => {
  13. const testJSON = '{ "name": hopp "url": true }'
  14. expect(() => jsonParse(testJSON)).toThrow()
  15. })
  16. test("thrown error has proper info fields", () => {
  17. expect.assertions(3)
  18. const testJSON = '{ "name": hopp "url": true }'
  19. try {
  20. jsonParse(testJSON)
  21. } catch (e) {
  22. expect(e).toHaveProperty("start")
  23. expect(e).toHaveProperty("end")
  24. expect(e).toHaveProperty("message")
  25. }
  26. })
  27. })