Skip to content

Commit 1152326

Browse files
committed
Add some small tests to improve coverage, still have more to work on though
1 parent 20cccd8 commit 1152326

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

async.test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,33 @@ modes.forEach((logic) => {
547547
})
548548
expect(answer).toStrictEqual([1, 3])
549549
})
550+
551+
test('async ??', async () => {
552+
logic.addMethod('asyncAdd', async ([a, b]) => a + b, { sync: false })
553+
554+
const answer = await logic.run({
555+
'??': [
556+
null,
557+
{ asyncAdd: [{ val: [] }, 2] }
558+
]
559+
}, 1)
560+
561+
expect(answer).toStrictEqual(3)
562+
})
563+
564+
test('async reduce', async () => {
565+
logic.addMethod('asyncAdd', async ([a, b]) => a + b, { sync: false })
566+
567+
const answer = await logic.build({
568+
reduce: [
569+
[1, 2, 3],
570+
{ asyncAdd: [{ val: 'accumulator' }, { val: 'current' }] },
571+
0
572+
]
573+
})
574+
575+
expect(await answer()).toStrictEqual(6)
576+
})
550577
})
551578

552579
describe('eachKey', () => {

general.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,4 +276,20 @@ describe('Various Test Cases', () => {
276276
for (const engine of normalEngines) await testEngine(engine, rule, badData, false)
277277
for (const engine of normalEngines) await testEngine(engine, rule, invalidData, false)
278278
})
279+
280+
it('should throw on a soft error when panic is used', async () => {
281+
const rule = {
282+
panic: { '+': 'hi' }
283+
}
284+
285+
for (const engine of normalEngines) await testEngine(engine, rule, {}, Error)
286+
for (const engine of permissiveEngines) await testEngine(engine, rule, {}, Error)
287+
288+
const rule2 = {
289+
panic: { error: 'Yeet' }
290+
}
291+
292+
for (const engine of normalEngines) await testEngine(engine, rule2, {}, Error)
293+
for (const engine of permissiveEngines) await testEngine(engine, rule2, {}, Error)
294+
})
279295
})

0 commit comments

Comments
 (0)