Skip to content

Commit 613425b

Browse files
committed
Add fail tests
1 parent a522080 commit 613425b

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

packages/expect/src/__tests__/toThrowMatchers.test.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,16 +297,39 @@ describe.each(['toThrowError', 'toThrow'] as const)('%s', toThrow => {
297297
});
298298

299299
test('isNot true, incorrect cause', () => {
300-
// less than v16 does not yet support Error.cause
301-
if (Number(process.version.split('.')[0].slice(1)) < 16) {
302-
expect(true).toBe(true);
303-
} else {
300+
// only v16 or higher support Error.cause
301+
if (Number(process.version.split('.')[0].slice(1)) >= 16) {
304302
jestExpect(() => {
305303
throw new Error('good', {cause: errorA});
306304
}).not[toThrow](expected);
307305
}
308306
});
309307
});
308+
309+
describe('fail', () => {
310+
// only v16 or higher support Error.cause
311+
if (Number(process.version.split('.')[0].slice(1)) >= 16) {
312+
test('isNot false, incorrect message', () => {
313+
expect(() =>
314+
jestExpect(() => {
315+
throw new Error('bad', {cause: errorB});
316+
})[toThrow](expected),
317+
).toThrow(
318+
/^(?=.*Expected message and cause: ).*Received message and cause: /s,
319+
);
320+
});
321+
322+
test('isNot true, incorrect cause', () => {
323+
expect(() =>
324+
jestExpect(() => {
325+
throw new Error('good', {cause: errorA});
326+
})[toThrow](expected),
327+
).toThrow(
328+
/^(?=.*Expected message and cause: ).*Received message and cause: /s,
329+
);
330+
});
331+
}
332+
});
310333
});
311334

312335
describe('asymmetric', () => {

0 commit comments

Comments
 (0)