-
-
Notifications
You must be signed in to change notification settings - Fork 200
Expand file tree
/
Copy pathtest.errors.js
More file actions
94 lines (86 loc) · 3.53 KB
/
test.errors.js
File metadata and controls
94 lines (86 loc) · 3.53 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import {checkBuiltInVMAndNodeVM} from '../test-helpers/checkVM.js';
checkBuiltInVMAndNodeVM(function (vmType, setBuiltInState) {
describe(`JSONPath - Error (${vmType})`, function () {
before(setBuiltInState);
it('should throw with missing `path`', function () {
assert.throws(() => {
jsonpath({json: []});
}, TypeError, 'You must supply a "path" property when providing an object ' +
'argument to JSONPath.evaluate().');
});
it('should throw with missing `json`', function () {
assert.throws(() => {
jsonpath({path: '$'});
}, TypeError, 'You must supply a "json" property when providing an object ' +
'argument to JSONPath.evaluate().');
});
it('should throw with a bad filter', () => {
expect(() => {
jsonpath({json: {book: []}, path: '$..[?(@.category === category)]'});
}).to.throw(Error, 'jsonPath: category is not defined: @.category === category');
});
it('should throw with a bad result type', () => {
expect(() => {
jsonpath({
json: {children: [5]},
path: '$..children',
resultType: 'badType'
});
}).to.throw(TypeError, 'Unknown result type');
});
it('should throw with `eval: false` and [?()] filtering expression', () => {
expect(() => {
const json = {
datafield: [
{"tag": "035", "subfield": {"@code": "a", "#text": "1879"}},
{"@tag": "042", "subfield": {"@code": "a", "#text": "5555"}},
{"@tag": "045", "045": "secret"}
]
};
jsonpath({
json,
path: "$.datafield[?(@.tag=='035')]",
eval: false
});
}).to.throw(Error, 'Eval [?(expr)] prevented in JSONPath expression.');
});
it('should throw with `eval: false` and [?()] filtering expression (@.length)', () => {
expect(() => {
const json = {
datafield: [
{"tag": "035", "subfield": {"@code": "a", "#text": "1879"}},
{"@tag": "042", "subfield": {"@code": "a", "#text": "5555"}},
{"@tag": "045", "045": "secret"}
]
};
jsonpath({
json,
path: '$..datafield[(@.length-1)]',
eval: false
});
}).to.throw(Error, 'Eval [(expr)] prevented in JSONPath expression.');
});
it('Syntax error in safe mode script', () => {
expect(() => {
const json = {tag: 10};
jsonpath({
json,
path: '$..[?(this)]',
wrap: false,
eval: 'safe'
});
}).to.throw(Error, 'jsonPath: Unexpected expression: this');
});
it('Invalid assignment in safe mode script', () => {
expect(() => {
const json = {tag: 10};
jsonpath({
json,
path: '$..[?(2 = 8)]',
wrap: false,
eval: 'safe'
});
}).to.throw(Error, 'jsonPath: Invalid left-hand side in assignment: 2 = 8');
});
});
});