Skip to content

Commit 38599d2

Browse files
committed
Add hard error tests
1 parent b65f0be commit 38599d2

File tree

2 files changed

+35
-9
lines changed

2 files changed

+35
-9
lines changed

compatible.test.js

+17-9
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,28 @@ describe('All of the compatible tests', () => {
5050
test(`${engine[1]} ${JSON.stringify(testCase.rule)} ${JSON.stringify(
5151
testCase.data
5252
)}`, async () => {
53-
let result = await engine[0].run(testCase.rule, testCase.data)
54-
if ((result || 0).toNumber) result = Number(result)
55-
if (Array.isArray(result)) result = result.map(i => (i || 0).toNumber ? Number(i) : i)
56-
expect(correction(result)).toStrictEqual(testCase.result)
53+
try {
54+
let result = await engine[0].run(testCase.rule, testCase.data)
55+
if ((result || 0).toNumber) result = Number(result)
56+
if (Array.isArray(result)) result = result.map(i => (i || 0).toNumber ? Number(i) : i)
57+
expect(correction(result)).toStrictEqual(testCase.result)
58+
} catch (err) {
59+
expect(testCase.error).toStrictEqual(true)
60+
}
5761
})
5862

5963
test(`${engine[1]} ${JSON.stringify(testCase.rule)} ${JSON.stringify(
6064
testCase.data
6165
)} (built)`, async () => {
62-
const f = await engine[0].build(testCase.rule)
63-
let result = await f(testCase.data)
64-
if ((result || 0).toNumber) result = Number(result)
65-
if (Array.isArray(result)) result = result.map(i => i.toNumber ? Number(i) : i)
66-
expect(correction(result)).toStrictEqual(testCase.result)
66+
try {
67+
const f = await engine[0].build(testCase.rule)
68+
let result = await f(testCase.data)
69+
if ((result || 0).toNumber) result = Number(result)
70+
if (Array.isArray(result)) result = result.map(i => i.toNumber ? Number(i) : i)
71+
expect(correction(result)).toStrictEqual(testCase.result)
72+
} catch (err) {
73+
expect(testCase.error).toStrictEqual(true)
74+
}
6775
})
6876
}
6977
}

suites/errors.json

+18
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,23 @@
2929
"rule": { "try": [{ "val": "x" }, 1]},
3030
"data": { "x": { "error": "Some error" }},
3131
"result": 1
32+
},
33+
{
34+
"description": "Can promote a soft error to a hard error with panic",
35+
"rule": { "panic": { "error": "Some error" } },
36+
"error": true,
37+
"data": null
38+
},
39+
{
40+
"description": "Panic with an error emitted from an operator",
41+
"rule": { "panic": [{ "/": [1, 0] }] },
42+
"error": true,
43+
"data": null
44+
},
45+
{
46+
"description": "Panic with an error pulled from context",
47+
"rule": { "panic": [{ "val": "x" }] },
48+
"error": true,
49+
"data": { "x": { "error": "Some error" } }
3250
}
3351
]

0 commit comments

Comments
 (0)