forked from sindresorhus/parse-json
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
45 lines (38 loc) · 848 Bytes
/
Copy pathtest.js
File metadata and controls
45 lines (38 loc) · 848 Bytes
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
33
34
35
36
37
38
39
40
41
42
43
44
45
import test from 'ava';
import parseJson from '.';
const jsonErrorRegex = /Unexpected token "}".*in foo\.json/;
test('main', t => {
t.truthy(parseJson('{"foo": true}'));
t.throws(() => {
parseJson('{\n\t"foo": true,\n}');
}, {
name: 'JSONError',
message: /Unexpected token "}"/
});
t.throws(() => {
try {
parseJson('{\n\t"foo": true,\n}');
} catch (error) {
error.fileName = 'foo.json';
throw error;
}
}, jsonErrorRegex);
t.throws(() => {
parseJson('{\n\t"foo": true,\n}', 'foo.json');
}, jsonErrorRegex);
t.throws(() => {
try {
parseJson('{\n\t"foo": true,\n}', 'bar.json');
} catch (error) {
error.fileName = 'foo.json';
throw error;
}
}, jsonErrorRegex);
});
test('throws exported error error', t => {
t.throws(() => {
parseJson('asdf');
}, {
instanceOf: parseJson.JSONError
});
});