From c1a2b772f4ce47e68d7448be78e26d03b2fca3a8 Mon Sep 17 00:00:00 2001 From: Don Schrimsher Date: Fri, 18 Jan 2019 20:00:13 -0500 Subject: [PATCH 1/8] Fix custom async matcher stack trace Fixes a bug causing custom async matcher stack traces to be lost. The issue was caused by the JestAssertionError being created after the promise for the async matcher resolved - by which point the stack containing the correct stack trace (pointing to the line where matcher was called) has been discarded. The issue was fixed by passing an error that is initialized before the promise resolves. --- packages/expect/src/index.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/expect/src/index.js b/packages/expect/src/index.js index ca6cacf16e3b..eaa52035242d 100644 --- a/packages/expect/src/index.js +++ b/packages/expect/src/index.js @@ -251,7 +251,10 @@ const makeThrowingMatcher = ( utils, }; - const processResult = (result: SyncExpectationResult) => { + const processResult = ( + result: SyncExpectationResult, + asyncError?: JestAssertionError, + ) => { _validateResult(result); getState().assertionCalls++; @@ -264,6 +267,9 @@ const makeThrowingMatcher = ( if (err) { error = err; error.message = message; + } else if (asyncError) { + error = asyncError; + error.message = message; } else { error = new JestAssertionError(message); @@ -307,9 +313,13 @@ const makeThrowingMatcher = ( if (isPromise((potentialResult: any))) { const asyncResult = ((potentialResult: any): AsyncExpectationResult); + const asyncError = new JestAssertionError(); + if (Error.captureStackTrace) { + Error.captureStackTrace(asyncError, throwingMatcher); + } return asyncResult - .then(aResult => processResult(aResult)) + .then(aResult => processResult(aResult, asyncError)) .catch(error => handlError(error)); } else { const syncResult = ((potentialResult: any): SyncExpectationResult); From 7f012f9fc2c9a5de384729cab89f69a860219d53 Mon Sep 17 00:00:00 2001 From: Don Schrimsher Date: Sat, 19 Jan 2019 09:38:21 -0500 Subject: [PATCH 2/8] Add test for custom async matcher stack trace fix Adds a test to verify the async custom matcher stack trace fix. --- .../customMatcherStackTrace.test.js.snap | 61 +++++++++++++++---- e2e/__tests__/customMatcherStackTrace.test.js | 10 ++- .../__tests__/async.test.js | 11 ++++ .../{customMatcher.test.js => sync.test.js} | 0 4 files changed, 70 insertions(+), 12 deletions(-) create mode 100644 e2e/custom-matcher-stack-trace/__tests__/async.test.js rename e2e/custom-matcher-stack-trace/__tests__/{customMatcher.test.js => sync.test.js} (100%) diff --git a/e2e/__tests__/__snapshots__/customMatcherStackTrace.test.js.snap b/e2e/__tests__/__snapshots__/customMatcherStackTrace.test.js.snap index 49b4afe4098c..4a6b5758e60d 100644 --- a/e2e/__tests__/__snapshots__/customMatcherStackTrace.test.js.snap +++ b/e2e/__tests__/__snapshots__/customMatcherStackTrace.test.js.snap @@ -1,12 +1,51 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`custom async matchers 1`] = ` +Object { + "rest": "FAIL __tests__/async.test.js + ✕ showing the stack trace for an async matcher + + ● showing the stack trace for an async matcher + + We expect the stack trace and code fence for this matcher to be shown in the console. + + 2 | + 3 | test('showing the stack trace for an async matcher', async () => { + > 4 | await expect(true).toThrowCustomAsyncMatcherError(); + | ^ + 5 | }); + 6 | + 7 | async function toThrowCustomAsyncMatcherError() { + + at Object.toThrowCustomAsyncMatcherError (__tests__/async.test.js:4:22) + +", + "summary": "Test Suites: 1 failed, 1 total +Tests: 1 failed, 1 total +Snapshots: 0 total +Time: <> +Ran all test suites matching /async.test.js/i. +", +} +`; + exports[`works with custom matchers 1`] = ` -"FAIL __tests__/customMatcher.test.js - Custom matcher - ✓ passes - ✓ fails - ✕ preserves error stack +"FAIL __tests__/async.test.js + ● showing the stack trace for an async matcher + + We expect the stack trace and code fence for this matcher to be shown in the console. + + 2 | + 3 | test('showing the stack trace for an async matcher', async () => { + > 4 | await expect(true).toThrowCustomAsyncMatcherError(); + | ^ + 5 | }); + 6 | + 7 | async function toThrowCustomAsyncMatcherError() { + + at Object.toThrowCustomAsyncMatcherError (__tests__/async.test.js:4:22) +FAIL __tests__/sync.test.js ● Custom matcher › preserves error stack qux @@ -19,12 +58,12 @@ exports[`works with custom matchers 1`] = ` 47 | 48 | // This expecation fails due to an error we throw (intentionally) - at Error (__tests__/customMatcher.test.js:45:13) - at baz (__tests__/customMatcher.test.js:43:23) - at bar (__tests__/customMatcher.test.js:42:23) - at foo (__tests__/customMatcher.test.js:52:7) - at Object.callback (__tests__/customMatcher.test.js:11:18) - at Object.toCustomMatch (__tests__/customMatcher.test.js:53:8) + at Error (__tests__/sync.test.js:45:13) + at baz (__tests__/sync.test.js:43:23) + at bar (__tests__/sync.test.js:42:23) + at foo (__tests__/sync.test.js:52:7) + at Object.callback (__tests__/sync.test.js:11:18) + at Object.toCustomMatch (__tests__/sync.test.js:53:8) " `; diff --git a/e2e/__tests__/customMatcherStackTrace.test.js b/e2e/__tests__/customMatcherStackTrace.test.js index 46d99eddea5c..36a2075758f4 100644 --- a/e2e/__tests__/customMatcherStackTrace.test.js +++ b/e2e/__tests__/customMatcherStackTrace.test.js @@ -12,7 +12,7 @@ import runJest from '../runJest'; import {extractSummary} from '../Utils'; test('works with custom matchers', () => { - const {stderr} = runJest('custom-matcher-stack-trace'); + const {stderr} = runJest('custom-matcher-stack-trace', ['sync.test.js']); let {rest} = extractSummary(stderr); @@ -23,3 +23,11 @@ test('works with custom matchers', () => { expect(rest).toMatchSnapshot(); }); + +test('custom async matchers', () => { + const {stderr} = runJest('custom-matcher-stack-trace', ['async.test.js']); + + const result = extractSummary(stderr); + + expect(result).toMatchSnapshot(); +}); diff --git a/e2e/custom-matcher-stack-trace/__tests__/async.test.js b/e2e/custom-matcher-stack-trace/__tests__/async.test.js new file mode 100644 index 000000000000..188eabbcfe0a --- /dev/null +++ b/e2e/custom-matcher-stack-trace/__tests__/async.test.js @@ -0,0 +1,11 @@ +expect.extend({toThrowCustomAsyncMatcherError}); + +test('showing the stack trace for an async matcher', async () => { + await expect(true).toThrowCustomAsyncMatcherError(); +}); + +async function toThrowCustomAsyncMatcherError() { + const message = () => + 'We expect the stack trace and code fence for this matcher to be shown in the console.'; + return {message, pass: false}; +} diff --git a/e2e/custom-matcher-stack-trace/__tests__/customMatcher.test.js b/e2e/custom-matcher-stack-trace/__tests__/sync.test.js similarity index 100% rename from e2e/custom-matcher-stack-trace/__tests__/customMatcher.test.js rename to e2e/custom-matcher-stack-trace/__tests__/sync.test.js From a1e1e4029fbad8099c439da6fa63858f0ddc4576 Mon Sep 17 00:00:00 2001 From: Don Schrimsher Date: Sat, 19 Jan 2019 10:01:04 -0500 Subject: [PATCH 3/8] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 07746d020b08..55ecda8ccbfc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -116,6 +116,7 @@ - `[jest-config]` Normalize `config.cwd` and `config.rootDir` using `realpath ([#7598](https://github.com/facebook/jest/pull/7598)) - `[jest-environment-node]` Fix buffer property is not ArrayBuffer issue. ([#7626](https://github.com/facebook/jest/pull/7626)) - `[babel-plugin-jest-hoist]` Ignore TS type annotations when looking for out-of-scope references ([#7641](https://github.com/facebook/jest/pull/7641)) +- `[expect]` Fix custom async matcher stack trace ([#7652](https://github.com/facebook/jest/pull/7652)) ### Chore & Maintenance From 023f108c65eba1960c4c9f4048de44df1bb11cfb Mon Sep 17 00:00:00 2001 From: Don Schrimsher Date: Mon, 21 Jan 2019 20:02:29 -0500 Subject: [PATCH 4/8] Use wrap in e2e test for custom matcher stack trace Uses the new wrap utility in e2e snapshot for custom matcher stack traces. --- .../customMatcherStackTrace.test.js.snap | 36 ++++--------------- e2e/__tests__/customMatcherStackTrace.test.js | 8 +++-- .../{async.test.js => asynchronous.test.js} | 0 3 files changed, 12 insertions(+), 32 deletions(-) rename e2e/custom-matcher-stack-trace/__tests__/{async.test.js => asynchronous.test.js} (100%) diff --git a/e2e/__tests__/__snapshots__/customMatcherStackTrace.test.js.snap b/e2e/__tests__/__snapshots__/customMatcherStackTrace.test.js.snap index 4a6b5758e60d..587b29269dee 100644 --- a/e2e/__tests__/__snapshots__/customMatcherStackTrace.test.js.snap +++ b/e2e/__tests__/__snapshots__/customMatcherStackTrace.test.js.snap @@ -1,8 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`custom async matchers 1`] = ` -Object { - "rest": "FAIL __tests__/async.test.js +FAIL __tests__/asynchronous.test.js ✕ showing the stack trace for an async matcher ● showing the stack trace for an async matcher @@ -17,35 +16,16 @@ Object { 6 | 7 | async function toThrowCustomAsyncMatcherError() { - at Object.toThrowCustomAsyncMatcherError (__tests__/async.test.js:4:22) - -", - "summary": "Test Suites: 1 failed, 1 total -Tests: 1 failed, 1 total -Snapshots: 0 total -Time: <> -Ran all test suites matching /async.test.js/i. -", -} + at Object.toThrowCustomAsyncMatcherError (__tests__/asynchronous.test.js:4:22) `; exports[`works with custom matchers 1`] = ` -"FAIL __tests__/async.test.js - ● showing the stack trace for an async matcher - - We expect the stack trace and code fence for this matcher to be shown in the console. - - 2 | - 3 | test('showing the stack trace for an async matcher', async () => { - > 4 | await expect(true).toThrowCustomAsyncMatcherError(); - | ^ - 5 | }); - 6 | - 7 | async function toThrowCustomAsyncMatcherError() { - - at Object.toThrowCustomAsyncMatcherError (__tests__/async.test.js:4:22) - FAIL __tests__/sync.test.js + Custom matcher + ✓ passes + ✓ fails + ✕ preserves error stack + ● Custom matcher › preserves error stack qux @@ -64,6 +44,4 @@ FAIL __tests__/sync.test.js at foo (__tests__/sync.test.js:52:7) at Object.callback (__tests__/sync.test.js:11:18) at Object.toCustomMatch (__tests__/sync.test.js:53:8) - -" `; diff --git a/e2e/__tests__/customMatcherStackTrace.test.js b/e2e/__tests__/customMatcherStackTrace.test.js index a4a8971d72b4..be338b2b7ee7 100644 --- a/e2e/__tests__/customMatcherStackTrace.test.js +++ b/e2e/__tests__/customMatcherStackTrace.test.js @@ -25,9 +25,11 @@ test('works with custom matchers', () => { }); test('custom async matchers', () => { - const {stderr} = runJest('custom-matcher-stack-trace', ['async.test.js']); + const {stderr} = runJest('custom-matcher-stack-trace', [ + 'asynchronous.test.js', + ]); - const result = extractSummary(stderr); + const {rest} = extractSummary(stderr); - expect(result).toMatchSnapshot(); + expect(wrap(rest)).toMatchSnapshot(); }); diff --git a/e2e/custom-matcher-stack-trace/__tests__/async.test.js b/e2e/custom-matcher-stack-trace/__tests__/asynchronous.test.js similarity index 100% rename from e2e/custom-matcher-stack-trace/__tests__/async.test.js rename to e2e/custom-matcher-stack-trace/__tests__/asynchronous.test.js From f2e50aa4b2a1153147bfac56d5e5a663b0189ec7 Mon Sep 17 00:00:00 2001 From: Don Schrimsher Date: Tue, 12 Feb 2019 19:47:20 -0500 Subject: [PATCH 5/8] Use Promise.resolve in expect async matcher tests --- .../expectAsyncMatcher.test.js.snap | 74 +++++++++++-------- .../__tests__/asynchronous.test.js | 7 ++ .../__tests__/failure.test.js | 24 +++--- 3 files changed, 60 insertions(+), 45 deletions(-) diff --git a/e2e/__tests__/__snapshots__/expectAsyncMatcher.test.js.snap b/e2e/__tests__/__snapshots__/expectAsyncMatcher.test.js.snap index 6ef5f68f3fca..6e45a320d5fb 100644 --- a/e2e/__tests__/__snapshots__/expectAsyncMatcher.test.js.snap +++ b/e2e/__tests__/__snapshots__/expectAsyncMatcher.test.js.snap @@ -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 @@ -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. (__tests__/failure.test.js:13:97) + at Object.toHaveLengthAsync (__tests__/failure.test.js:22:41) ● fail with expected promise values and not @@ -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 diff --git a/e2e/custom-matcher-stack-trace/__tests__/asynchronous.test.js b/e2e/custom-matcher-stack-trace/__tests__/asynchronous.test.js index 188eabbcfe0a..33061bffa53e 100644 --- a/e2e/custom-matcher-stack-trace/__tests__/asynchronous.test.js +++ b/e2e/custom-matcher-stack-trace/__tests__/asynchronous.test.js @@ -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 () => { diff --git a/e2e/expect-async-matcher/__tests__/failure.test.js b/e2e/expect-async-matcher/__tests__/failure.test.js index e10b1947c556..6041e119bec9 100644 --- a/e2e/expect-async-matcher/__tests__/failure.test.js +++ b/e2e/expect-async-matcher/__tests__/failure.test.js @@ -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) - ); -}); + )); From c38615e838b8c6d1564bf903ba974b0c0ef4cc2d Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Wed, 13 Feb 2019 09:32:37 +0100 Subject: [PATCH 6/8] chore: move changelog entry --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a2592e3439b..ca91b9d179c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ ### Fixes - `[jest-cli]` Refactor `-o` and `--coverage` combined ([#7611](https://github.com/facebook/jest/pull/7611)) +- `[expect]` Fix custom async matcher stack trace ([#7652](https://github.com/facebook/jest/pull/7652)) ### Chore & Maintenance @@ -191,7 +192,6 @@ - `[jest-config]` Normalize `config.cwd` and `config.rootDir` using `realpath ([#7598](https://github.com/facebook/jest/pull/7598)) - `[jest-environment-node]` Fix buffer property is not ArrayBuffer issue. ([#7626](https://github.com/facebook/jest/pull/7626)) - `[babel-plugin-jest-hoist]` Ignore TS type annotations when looking for out-of-scope references ([#7641](https://github.com/facebook/jest/pull/7641)) -- `[expect]` Fix custom async matcher stack trace ([#7652](https://github.com/facebook/jest/pull/7652)) - `[jest-config]` Add name to project if one does not exist to pick correct resolver ([#5862](https://github.com/facebook/jest/pull/5862)) - `[jest-runtime]` Pass `watchPathIgnorePatterns` to Haste instance ([#7585](https://github.com/facebook/jest/pull/7585)) - `[jest-runtime]` Resolve mock files via Haste when using `require.resolve` ([#7687](https://github.com/facebook/jest/pull/7687)) From 7ac2a3c5a83eae4b13710b63fe7f7d1d343f3af0 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Wed, 13 Feb 2019 09:36:40 +0100 Subject: [PATCH 7/8] normalize tests --- .../expectAsyncMatcher.test.js.snap | 62 +++++++++---------- .../__tests__/failure.test.js | 7 +-- .../__tests__/success.test.js | 29 +++------ 3 files changed, 41 insertions(+), 57 deletions(-) diff --git a/e2e/__tests__/__snapshots__/expectAsyncMatcher.test.js.snap b/e2e/__tests__/__snapshots__/expectAsyncMatcher.test.js.snap index 6e45a320d5fb..b7d07fa98db9 100644 --- a/e2e/__tests__/__snapshots__/expectAsyncMatcher.test.js.snap +++ b/e2e/__tests__/__snapshots__/expectAsyncMatcher.test.js.snap @@ -16,15 +16,15 @@ FAIL __tests__/failure.test.js received.length: 1 - 14 | - 15 | it('fail with expected non promise values', () => - > 16 | expect([1]).toHaveLengthAsync(Promise.resolve(2))); + 11 | + 12 | it('fail with expected non promise values', () => + > 13 | 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))); + 14 | + 15 | it('fail with expected non promise values and not', () => + 16 | expect([1, 2]).not.toHaveLengthAsync(Promise.resolve(2))); - at Object.toHaveLengthAsync (__tests__/failure.test.js:16:15) + at Object.toHaveLengthAsync (__tests__/failure.test.js:13:15) ● fail with expected non promise values and not @@ -35,15 +35,15 @@ FAIL __tests__/failure.test.js received.length: 2 - 17 | - 18 | it('fail with expected non promise values and not', () => - > 19 | expect([1, 2]).not.toHaveLengthAsync(Promise.resolve(2))); + 14 | + 15 | it('fail with expected non promise values and not', () => + > 16 | 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))); + 17 | + 18 | it('fail with expected promise values', () => + 19 | expect(Promise.resolve([1])).resolves.toHaveLengthAsync(Promise.resolve(2))); - at Object.toHaveLengthAsync (__tests__/failure.test.js:19:22) + at Object.toHaveLengthAsync (__tests__/failure.test.js:16:22) ● fail with expected promise values @@ -54,15 +54,15 @@ FAIL __tests__/failure.test.js received.length: 1 - 20 | - 21 | it('fail with expected promise values', () => - > 22 | expect(Promise.resolve([1])).resolves.toHaveLengthAsync(Promise.resolve(2))); + 17 | + 18 | it('fail with expected promise values', () => + > 19 | 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( + 20 | + 21 | it('fail with expected promise values and not', () => + 22 | expect(Promise.resolve([1, 2])).resolves.not.toHaveLengthAsync( - at Object.toHaveLengthAsync (__tests__/failure.test.js:22:41) + at Object.toHaveLengthAsync (__tests__/failure.test.js:19:41) ● fail with expected promise values and not @@ -73,17 +73,13 @@ 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( + 20 | + 21 | it('fail with expected promise values and not', () => + > 22 | expect(Promise.resolve([1, 2])).resolves.not.toHaveLengthAsync( | ^ - 26 | Promise.resolve(2) - 27 | )); - 28 | - - 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 - at Object. (__tests__/failure.test.js:13:97) + 23 | Promise.resolve(2) + 24 | )); + 25 | + + at Object.toHaveLengthAsync (__tests__/failure.test.js:22:48) `; diff --git a/e2e/expect-async-matcher/__tests__/failure.test.js b/e2e/expect-async-matcher/__tests__/failure.test.js index 6041e119bec9..206948d90a9b 100644 --- a/e2e/expect-async-matcher/__tests__/failure.test.js +++ b/e2e/expect-async-matcher/__tests__/failure.test.js @@ -4,13 +4,10 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ -'use strict'; import {toHaveLengthAsync} from '../matchers'; -expect.extend({ - toHaveLengthAsync, -}); +expect.extend({toHaveLengthAsync}); it('fail with expected non promise values', () => expect([1]).toHaveLengthAsync(Promise.resolve(2))); @@ -21,7 +18,7 @@ it('fail with expected non promise values and not', () => it('fail with expected promise values', () => expect(Promise.resolve([1])).resolves.toHaveLengthAsync(Promise.resolve(2))); -it('fail with expected promise values and not', async () => +it('fail with expected promise values and not', () => expect(Promise.resolve([1, 2])).resolves.not.toHaveLengthAsync( Promise.resolve(2) )); diff --git a/e2e/expect-async-matcher/__tests__/success.test.js b/e2e/expect-async-matcher/__tests__/success.test.js index ac3a8a738b94..8f597b9788ea 100644 --- a/e2e/expect-async-matcher/__tests__/success.test.js +++ b/e2e/expect-async-matcher/__tests__/success.test.js @@ -4,30 +4,21 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ -'use strict'; import {toHaveLengthAsync} from '../matchers'; -expect.extend({ - toHaveLengthAsync, -}); +expect.extend({toHaveLengthAsync}); -it('works with expected non promise values', async () => { - await (expect([1]): any).toHaveLengthAsync(Promise.resolve(1)); -}); +it('works with expected non promise values', () => + expect([1]).toHaveLengthAsync(Promise.resolve(1))); -it('works with expected non promise values and not', async () => { - await (expect([1, 2]): any).not.toHaveLengthAsync(Promise.resolve(1)); -}); +it('works with expected non promise values and not', () => + expect([1, 2]).not.toHaveLengthAsync(Promise.resolve(1))); -it('works with expected promise values', async () => { - await (expect(Promise.resolve([1])).resolves: any).toHaveLengthAsync( - Promise.resolve(1) - ); -}); +it('works with expected promise values', () => + expect(Promise.resolve([1])).resolves.toHaveLengthAsync(Promise.resolve(1))); -it('works with expected promise values and not', async () => { - await (expect(Promise.resolve([1, 2])).resolves.not: any).toHaveLengthAsync( +it('works with expected promise values and not', () => + expect(Promise.resolve([1, 2])).resolves.not.toHaveLengthAsync( Promise.resolve(1) - ); -}); + )); From ef15826ae38dd77cbdafe3eb56b05c496be4e4e7 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Wed, 13 Feb 2019 09:39:08 +0100 Subject: [PATCH 8/8] update snapshot --- .../customMatcherStackTrace.test.js.snap | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/e2e/__tests__/__snapshots__/customMatcherStackTrace.test.js.snap b/e2e/__tests__/__snapshots__/customMatcherStackTrace.test.js.snap index 587b29269dee..15df98763079 100644 --- a/e2e/__tests__/__snapshots__/customMatcherStackTrace.test.js.snap +++ b/e2e/__tests__/__snapshots__/customMatcherStackTrace.test.js.snap @@ -8,15 +8,15 @@ FAIL __tests__/asynchronous.test.js We expect the stack trace and code fence for this matcher to be shown in the console. - 2 | - 3 | test('showing the stack trace for an async matcher', async () => { - > 4 | await expect(true).toThrowCustomAsyncMatcherError(); - | ^ - 5 | }); - 6 | - 7 | async function toThrowCustomAsyncMatcherError() { - - at Object.toThrowCustomAsyncMatcherError (__tests__/asynchronous.test.js:4:22) + 9 | + 10 | test('showing the stack trace for an async matcher', async () => { + > 11 | await expect(true).toThrowCustomAsyncMatcherError(); + | ^ + 12 | }); + 13 | + 14 | async function toThrowCustomAsyncMatcherError() { + + at Object.toThrowCustomAsyncMatcherError (__tests__/asynchronous.test.js:11:22) `; exports[`works with custom matchers 1`] = `