index.js 586 B

1234567891011121314151617181920212223242526
  1. var test = require("tape")
  2. var safeParse = require("../index")
  3. test("safeParse is a function", function (assert) {
  4. assert.equal(typeof safeParse, "function")
  5. assert.end()
  6. })
  7. test("safeParse valid json", function (assert) {
  8. safeParse("{ \"foo\": true }", function (err, json) {
  9. assert.ifError(err)
  10. assert.equal(json.foo, true)
  11. assert.end()
  12. })
  13. })
  14. test("safeParse faulty", function (assert) {
  15. safeParse("WRONG", function (err) {
  16. assert.ok(err)
  17. assert.equal(err.message, "Unexpected token W")
  18. assert.end()
  19. })
  20. })