Skip to content

Commit 4a6fcc9

Browse files
committed
test: add test for higher coverage
1 parent 7a491fd commit 4a6fcc9

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,15 @@ Received function did not throw
9595
Returned: undefined
9696
`;
9797

98+
exports[`toThrow error class did not throw at all with a promise 1`] = `
99+
<d>expect(</><r>received</><d>).</>toThrow<d>(</><g>expected</><d>)</>
100+
101+
<b>Matcher error</>: <r>received</> value must be a function
102+
103+
Received has type: object
104+
Received has value: <r>{}</>
105+
`;
106+
98107
exports[`toThrow error class threw, but class did not match (error) 1`] = `
99108
<d>expect(</><r>received</><d>).</>toThrow<d>(</><g>expected</><d>)</>
100109

@@ -234,6 +243,15 @@ Received function did not throw
234243
Returned: undefined
235244
`;
236245

246+
exports[`toThrow regexp did not throw at all with a promise 1`] = `
247+
<d>expect(</><r>received</><d>).</>toThrow<d>(</><g>expected</><d>)</>
248+
249+
<b>Matcher error</>: <r>received</> value must be a function
250+
251+
Received has type: object
252+
Received has value: <r>{}</>
253+
`;
254+
237255
exports[`toThrow regexp threw, but message did not match (error) 1`] = `
238256
<d>expect(</><r>received</><d>).</>toThrow<d>(</><g>expected</><d>)</>
239257

@@ -277,6 +295,15 @@ Received function did not throw
277295
Returned: undefined
278296
`;
279297

298+
exports[`toThrow substring did not throw with a promise 1`] = `
299+
<d>expect(</><r>received</><d>).</>toThrow<d>(</><g>expected</><d>)</>
300+
301+
<b>Matcher error</>: <r>received</> value must be a function
302+
303+
Received has type: object
304+
Received has value: <r>{}</>
305+
`;
306+
280307
exports[`toThrow substring threw, but message did not match (error) 1`] = `
281308
<d>expect(</><r>received</><d>).</>toThrow<d>(</><g>expected</><d>)</>
282309

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ describe('toThrow', () => {
5050
).toThrowErrorMatchingSnapshot();
5151
});
5252

53+
test('did not throw with a promise', () => {
54+
expect(() =>
55+
jestExpect(Promise.resolve('banana')).toThrow('apple'),
56+
).toThrowErrorMatchingSnapshot();
57+
});
58+
5359
test('threw, but message did not match (error)', () => {
5460
expect(() => {
5561
jestExpect(() => {
@@ -108,6 +114,12 @@ describe('toThrow', () => {
108114
).toThrowErrorMatchingSnapshot();
109115
});
110116

117+
test('did not throw at all with a promise', () => {
118+
expect(() =>
119+
jestExpect(Promise.resolve('banana')).toThrow(/apple/),
120+
).toThrowErrorMatchingSnapshot();
121+
});
122+
111123
test('threw, but message did not match (error)', () => {
112124
expect(() => {
113125
jestExpect(() => {
@@ -187,6 +199,12 @@ describe('toThrow', () => {
187199
).toThrowErrorMatchingSnapshot();
188200
});
189201

202+
test('did not throw at all with a promise', () => {
203+
expect(() =>
204+
jestExpect(Promise.resolve()).toThrow(Err),
205+
).toThrowErrorMatchingSnapshot();
206+
});
207+
190208
test('threw, but class did not match (error)', () => {
191209
expect(() => {
192210
jestExpect(() => {

0 commit comments

Comments
 (0)