From 32afd4edc44f9c1a95958ab1aed37d4af85e3009 Mon Sep 17 00:00:00 2001 From: Matt Phillips Date: Sat, 29 Sep 2018 14:10:39 +0100 Subject: [PATCH] Add error with stack useage to test.todo --- packages/jest-circus/src/index.js | 16 +++++----------- packages/jest-jasmine2/src/jasmine/Env.js | 12 +++++------- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/packages/jest-circus/src/index.js b/packages/jest-circus/src/index.js index 3802758a5855..536a4c25a4ae 100644 --- a/packages/jest-circus/src/index.js +++ b/packages/jest-circus/src/index.js @@ -114,19 +114,13 @@ test.only = (testName: TestName, fn: TestFn, timeout?: number) => { test.todo = (testName: TestName, ...rest: Array) => { if (rest.length > 0 || typeof testName !== 'string') { - const e = new Error('Todo must be called with only a description.'); - - if (Error.captureStackTrace) { - Error.captureStackTrace(e, test.todo); - } - - throw e; + throw new ErrorWithStack( + 'Todo must be called with only a description.', + test.todo, + ); } - const asyncError = new Error(); - if (Error.captureStackTrace) { - Error.captureStackTrace(asyncError, test); - } + const asyncError = new ErrorWithStack(undefined, test); return dispatch({ asyncError, diff --git a/packages/jest-jasmine2/src/jasmine/Env.js b/packages/jest-jasmine2/src/jasmine/Env.js index 0e94b1b46f5d..5b184b4efbb4 100644 --- a/packages/jest-jasmine2/src/jasmine/Env.js +++ b/packages/jest-jasmine2/src/jasmine/Env.js @@ -35,6 +35,7 @@ import queueRunner from '../queue_runner'; import treeProcessor from '../tree_processor'; import checkIsError from '../is_error'; import assertionErrorMessage from '../assert_support'; +import {ErrorWithStack} from 'jest-util'; // Try getting the real promise object from the context, if available. Someone // could have overridden it in a test. Async functions return it implicitly. @@ -497,13 +498,10 @@ export default function(j$) { this.todo = function() { const description = arguments[0]; if (arguments.length !== 1 || typeof description !== 'string') { - const e = new Error('Todo must be called with only a description.'); - - if (Error.captureStackTrace) { - Error.captureStackTrace(e, test.todo); - } - - throw e; + throw new ErrorWithStack( + 'Todo must be called with only a description.', + test.todo, + ); } const spec = specFactory(description, () => {}, currentDeclarationSuite);