Skip to content

Commit

Permalink
Use Promise.resolve in expect async matcher tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Don Schrimsher committed Feb 13, 2019
1 parent 5f91b0f commit f2e50aa
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 45 deletions.
74 changes: 44 additions & 30 deletions e2e/__tests__/__snapshots__/expectAsyncMatcher.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,40 @@ FAIL __tests__/failure.test.js
● fail with expected non promise values
Expected value to have length:
2
Received:
1
received.length:
1
2
Received:
1
received.length:
1
14 |
15 | it('fail with expected non promise values', () =>
> 16 | expect([1]).toHaveLengthAsync(Promise.resolve(2)));
| ^
17 |
18 | it('fail with expected non promise values and not', () =>
19 | expect([1, 2]).not.toHaveLengthAsync(Promise.resolve(2)));
at Object.toHaveLengthAsync (__tests__/failure.test.js:16:15)
● fail with expected non promise values and not
Expected value to not have length:
2
Received:
1,2
received.length:
2
2
Received:
1,2
received.length:
2
17 |
18 | it('fail with expected non promise values and not', () =>
> 19 | expect([1, 2]).not.toHaveLengthAsync(Promise.resolve(2)));
| ^
20 |
21 | it('fail with expected promise values', () =>
22 | expect(Promise.resolve([1])).resolves.toHaveLengthAsync(Promise.resolve(2)));
at Object.toHaveLengthAsync (__tests__/failure.test.js:19:22)
● fail with expected promise values
Expand All @@ -36,19 +54,15 @@ FAIL __tests__/failure.test.js
received.length:
1
22 |
23 | it('fail with expected promise values', async () => {
> 24 | await (expect(Promise.resolve([1])): any).resolves.toHaveLengthAsync(
| ^
25 | Promise.resolve(2)
26 | );
27 | });
20 |
21 | it('fail with expected promise values', () =>
> 22 | expect(Promise.resolve([1])).resolves.toHaveLengthAsync(Promise.resolve(2)));
| ^
23 |
24 | it('fail with expected promise values and not', async () =>
25 | expect(Promise.resolve([1, 2])).resolves.not.toHaveLengthAsync(
at Object.toHaveLengthAsync (__tests__/failure.test.js:24:54)
at asyncGeneratorStep (__tests__/failure.test.js:11:103)
at _next (__tests__/failure.test.js:13:194)
at __tests__/failure.test.js:13:364
at Object.<anonymous> (__tests__/failure.test.js:13:97)
at Object.toHaveLengthAsync (__tests__/failure.test.js:22:41)
● fail with expected promise values and not
Expand All @@ -59,15 +73,15 @@ FAIL __tests__/failure.test.js
received.length:
2
23 |
24 | it('fail with expected promise values and not', async () =>
> 25 | expect(Promise.resolve([1, 2])).resolves.not.toHaveLengthAsync(
| ^
26 | Promise.resolve(2)
27 | ));
28 |
29 | it('fail with expected promise values and not', async () => {
> 30 | await (expect(Promise.resolve([1, 2])).resolves.not: any).toHaveLengthAsync(
| ^
31 | Promise.resolve(2)
32 | );
33 | });
at Object.toHaveLengthAsync (__tests__/failure.test.js:30:61)
at Object.toHaveLengthAsync (__tests__/failure.test.js:25:48)
at asyncGeneratorStep (__tests__/failure.test.js:11:103)
at _next (__tests__/failure.test.js:13:194)
at __tests__/failure.test.js:13:364
Expand Down
7 changes: 7 additions & 0 deletions e2e/custom-matcher-stack-trace/__tests__/asynchronous.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

expect.extend({toThrowCustomAsyncMatcherError});

test('showing the stack trace for an async matcher', async () => {
Expand Down
24 changes: 9 additions & 15 deletions e2e/expect-async-matcher/__tests__/failure.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,16 @@ expect.extend({
toHaveLengthAsync,
});

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

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

it('fail with expected promise values', async () => {
await (expect(Promise.resolve([1])): any).resolves.toHaveLengthAsync(
Promise.resolve(2)
);
});
it('fail with expected promise values', () =>
expect(Promise.resolve([1])).resolves.toHaveLengthAsync(Promise.resolve(2)));

it('fail with expected promise values and not', async () => {
await (expect(Promise.resolve([1, 2])).resolves.not: any).toHaveLengthAsync(
it('fail with expected promise values and not', async () =>
expect(Promise.resolve([1, 2])).resolves.not.toHaveLengthAsync(
Promise.resolve(2)
);
});
));

0 comments on commit f2e50aa

Please sign in to comment.