Skip to content

Commit 010b36a

Browse files
committed
test: add more invalid json tests
1 parent cdab6fe commit 010b36a

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

test/parallel/test-json-parser.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ describe('node:json', () => {
5353
);
5454
});
5555

56-
test('throws SyntaxError on invalid JSON', () => {
56+
test('throws SyntaxError on invalid string JSON', () => {
5757
assert.throws(
5858
() => parse('not valid json'),
5959
{
@@ -62,6 +62,24 @@ describe('node:json', () => {
6262
);
6363
});
6464

65+
test('throws SyntaxError on invalid object JSON', () => {
66+
assert.throws(
67+
() => parse('{"key": "property}'),
68+
{
69+
name: 'SyntaxError',
70+
}
71+
);
72+
});
73+
74+
test('throws SyntaxError on invalid array JSON', () => {
75+
assert.throws(
76+
() => parse('[1,2,3,]'),
77+
{
78+
name: 'SyntaxError',
79+
}
80+
);
81+
});
82+
6583
test('parses simple object', () => {
6684
const result = parse('{"key":"value"}');
6785
assert.deepStrictEqual(result, { key: 'value' });

0 commit comments

Comments
 (0)