Skip to content

Commit

Permalink
Add error with stack useage to test.todo
Browse files Browse the repository at this point in the history
  • Loading branch information
mattphillips committed Sep 29, 2018
1 parent ad25ed3 commit 32afd4e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
16 changes: 5 additions & 11 deletions packages/jest-circus/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,13 @@ test.only = (testName: TestName, fn: TestFn, timeout?: number) => {

test.todo = (testName: TestName, ...rest: Array<mixed>) => {
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,
Expand Down
12 changes: 5 additions & 7 deletions packages/jest-jasmine2/src/jasmine/Env.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 32afd4e

Please sign in to comment.