forked from JSONPath-Plus/JSONPath
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.errors.js
More file actions
70 lines (64 loc) · 2.75 KB
/
Copy pathtest.errors.js
File metadata and controls
70 lines (64 loc) · 2.75 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
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: _$_v.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 `preventEval` 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')]",
preventEval: true
});
}).to.throw(Error, 'Eval [?(expr)] prevented in JSONPath expression.');
});
it('should throw with `preventEval` 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[(@.length-1)]',
preventEval: true
});
}).to.throw(Error, 'Eval [(expr)] prevented in JSONPath expression.');
});
});
});