Welcome to mirror list, hosted at ThFree Co, Russian Federation.

test.js « test « json-parse-helpfulerror « node_modules « read-package-json « node_modules - github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: fca458ac080f60a2e86a325dadbdcd798fde1d6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
var Code = require('code'),
    Lab = require('lab'),
    lab = Lab.script(),
    jph = require('..'); // 'json-parse-helpfulerror'

exports.lab = lab;

lab.test('can parse', function (done) {
  var o = jph.parse('{"foo": "bar"}');

  Code.expect(o.foo).to.equal('bar');
  done();
});

lab.test('helpful error for bad JSON', function (done) {

  var bad = "{'foo': 'bar'}";

  Code.expect(function () { JSON.parse(bad) }).to.throw();

  Code.expect(function () { jph.parse(bad) }).to.throw(SyntaxError, "Unexpected token '\\'' at 1:2\n" + bad + '\n ^');

  done();
});

lab.test('fails if reviver throws', function (done) {
  function badReviver() { throw new ReferenceError('silly'); }

  Code.expect(function () { jph.parse('3', badReviver) }).to.throw(ReferenceError, 'silly');

  done();
});