Closed panva closed 2 years ago
Thanks 👍 , I'll get a look.
Must be overlooking something.
While the assert part is correct and works in unit tests, failed or succeeding use of it inside test()
doesn't get picked up... Something with onResult
and the fact that the assertion result is resolved by a promise, not immediately returned.
Must be overlooking something.
While the assert part is correct and works in unit tests, failed or succeeding use of it inside
test()
doesn't get picked up... Something withonResult
and the fact that the assertion result is resolved by a promise, not immediately returned.
Yep, assertion functions should be simple pure functions. The fact it is almost the same as the "throws" operator is also a code smell to me.
It has more to do with the control flow than an actual assertion (throws
as well, but it was already part of the library).
try{
await throwingFunc();
t.fail('should not get here')
} catch(e){
t.ok(e instanceof MyCustomError);
}
is probably more verbose, but more explicit of what we test/expect, which is always better in my opinion than saving few lines.
You can always put it in a helper:
export const testAsync = ({assert, fn}) => {
try{
await fn();
assert.fail('should not get here')
} catch(e){
assert.ok(e instanceof MyCustomError);
}
}
I found this useful assertion missing. Its implementation is inspired by
throws
from zora.