Reputation: 3766
Node's documentation of assert
module for assert.ifError
Throws value if value is not undefined or null. This is useful when testing the error argument in callbacks. The stack trace contains all frames from the error passed to ifError() including the potential new frames for ifError() itself.
assert.ifError(null);
// OK
assert.ifError(0);
// AssertionError [ERR_ASSERTION]: ifError got unwanted exception: 0
assert.ifError('error');
// AssertionError [ERR_ASSERTION]: ifError got unwanted exception: 'error'
assert.ifError(new Error());
// AssertionError [ERR_ASSERTION]: ifError got unwanted exception: Error
What is Jest alternative for asser.IfError
?
Upvotes: 0
Views: 264
Reputation: 3766
OK i figured it out.
expect.toContain
matcher.expect([undefined, null]).toContain(value);
jest.extended
module toBeNil
methodyarn add -D jest-extended
Use .toBeNil
when checking a value is null
or undefined
.
test('passes when value is null or undefined', () => {
expect(null).toBeNil();
expect(undefined).toBeNil();
expect(true).not.toBeNil();
});
Upvotes: 1