Skip to content

Commit 221263f

Browse files
author
Don Schrimsher
committed
Use Promise.resolve in expect async matcher tests
1 parent 5f91b0f commit 221263f

File tree

2 files changed

+53
-45
lines changed

2 files changed

+53
-45
lines changed

e2e/__tests__/__snapshots__/expectAsyncMatcher.test.js.snap

Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,40 @@ FAIL __tests__/failure.test.js
1010
● fail with expected non promise values
1111
1212
Expected value to have length:
13+
2
14+
Received:
15+
1
16+
received.length:
17+
1
1318
14-
2
15-
Received:
16-
1
17-
received.length:
18-
1
19+
14 |
20+
15 | it('fail with expected non promise values', () =>
21+
> 16 | expect([1]).toHaveLengthAsync(Promise.resolve(2)));
22+
| ^
23+
17 |
24+
18 | it('fail with expected non promise values and not', () =>
25+
19 | expect([1, 2]).not.toHaveLengthAsync(Promise.resolve(2)));
26+
27+
at Object.toHaveLengthAsync (__tests__/failure.test.js:16:15)
1928
2029
● fail with expected non promise values and not
2130
2231
Expected value to not have length:
32+
2
33+
Received:
34+
1,2
35+
received.length:
36+
2
2337
24-
2
25-
Received:
26-
1,2
27-
received.length:
28-
2
38+
17 |
39+
18 | it('fail with expected non promise values and not', () =>
40+
> 19 | expect([1, 2]).not.toHaveLengthAsync(Promise.resolve(2)));
41+
| ^
42+
20 |
43+
21 | it('fail with expected promise values', () =>
44+
22 | expect(Promise.resolve([1])).resolves.toHaveLengthAsync(Promise.resolve(2)));
45+
46+
at Object.toHaveLengthAsync (__tests__/failure.test.js:19:22)
2947
3048
● fail with expected promise values
3149
@@ -36,19 +54,15 @@ FAIL __tests__/failure.test.js
3654
received.length:
3755
1
3856
39-
22 |
40-
23 | it('fail with expected promise values', async () => {
41-
> 24 | await (expect(Promise.resolve([1])): any).resolves.toHaveLengthAsync(
42-
| ^
43-
25 | Promise.resolve(2)
44-
26 | );
45-
27 | });
57+
20 |
58+
21 | it('fail with expected promise values', () =>
59+
> 22 | expect(Promise.resolve([1])).resolves.toHaveLengthAsync(Promise.resolve(2)));
60+
| ^
61+
23 |
62+
24 | it('fail with expected promise values and not', async () =>
63+
25 | expect(Promise.resolve([1, 2])).resolves.not.toHaveLengthAsync(
4664
47-
at Object.toHaveLengthAsync (__tests__/failure.test.js:24:54)
48-
at asyncGeneratorStep (__tests__/failure.test.js:11:103)
49-
at _next (__tests__/failure.test.js:13:194)
50-
at __tests__/failure.test.js:13:364
51-
at Object.<anonymous> (__tests__/failure.test.js:13:97)
65+
at Object.toHaveLengthAsync (__tests__/failure.test.js:22:41)
5266
5367
● fail with expected promise values and not
5468
@@ -59,15 +73,15 @@ FAIL __tests__/failure.test.js
5973
received.length:
6074
2
6175
76+
23 |
77+
24 | it('fail with expected promise values and not', async () =>
78+
> 25 | expect(Promise.resolve([1, 2])).resolves.not.toHaveLengthAsync(
79+
| ^
80+
26 | Promise.resolve(2)
81+
27 | ));
6282
28 |
63-
29 | it('fail with expected promise values and not', async () => {
64-
> 30 | await (expect(Promise.resolve([1, 2])).resolves.not: any).toHaveLengthAsync(
65-
| ^
66-
31 | Promise.resolve(2)
67-
32 | );
68-
33 | });
69-
70-
at Object.toHaveLengthAsync (__tests__/failure.test.js:30:61)
83+
84+
at Object.toHaveLengthAsync (__tests__/failure.test.js:25:48)
7185
at asyncGeneratorStep (__tests__/failure.test.js:11:103)
7286
at _next (__tests__/failure.test.js:13:194)
7387
at __tests__/failure.test.js:13:364

e2e/expect-async-matcher/__tests__/failure.test.js

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,16 @@ expect.extend({
1212
toHaveLengthAsync,
1313
});
1414

15-
it('fail with expected non promise values', async () => {
16-
await (expect([1]): any).toHaveLengthAsync(Promise.resolve(2));
17-
});
15+
it('fail with expected non promise values', () =>
16+
expect([1]).toHaveLengthAsync(Promise.resolve(2)));
1817

19-
it('fail with expected non promise values and not', async () => {
20-
await (expect([1, 2]): any).not.toHaveLengthAsync(Promise.resolve(2));
21-
});
18+
it('fail with expected non promise values and not', () =>
19+
expect([1, 2]).not.toHaveLengthAsync(Promise.resolve(2)));
2220

23-
it('fail with expected promise values', async () => {
24-
await (expect(Promise.resolve([1])): any).resolves.toHaveLengthAsync(
25-
Promise.resolve(2)
26-
);
27-
});
21+
it('fail with expected promise values', () =>
22+
expect(Promise.resolve([1])).resolves.toHaveLengthAsync(Promise.resolve(2)));
2823

29-
it('fail with expected promise values and not', async () => {
30-
await (expect(Promise.resolve([1, 2])).resolves.not: any).toHaveLengthAsync(
24+
it('fail with expected promise values and not', async () =>
25+
expect(Promise.resolve([1, 2])).resolves.not.toHaveLengthAsync(
3126
Promise.resolve(2)
32-
);
33-
});
27+
));

0 commit comments

Comments
 (0)