-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add stack trace on expect.(has)Assertions #5997
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -314,19 +314,34 @@ const _validateResult = result => { | |
} | ||
}; | ||
|
||
function assertions(expected: number) { | ||
const error = new Error(); | ||
if (Error.captureStackTrace) { | ||
Error.captureStackTrace(error, assertions); | ||
} | ||
|
||
getState().expectedAssertionsNumber = expected; | ||
getState().expectedAssertionsNumberError = error; | ||
} | ||
function hasAssertions(...args) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. has to be a flow bug that I was only yelled at after extracting this (complaining that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Curious what caused this (would be great to setup a repro for Flow folks). But There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, unable to reproduce in their repl... |
||
const error = new Error(); | ||
if (Error.captureStackTrace) { | ||
Error.captureStackTrace(error, hasAssertions); | ||
} | ||
|
||
utils.ensureNoExpected(args[0], '.hasAssertions'); | ||
getState().isExpectingAssertions = true; | ||
getState().isExpectingAssertionsError = error; | ||
} | ||
|
||
// add default jest matchers | ||
setMatchers(matchers, true, expect); | ||
setMatchers(spyMatchers, true, expect); | ||
setMatchers(toThrowMatchers, true, expect); | ||
|
||
expect.addSnapshotSerializer = () => void 0; | ||
expect.assertions = (expected: number) => { | ||
getState().expectedAssertionsNumber = expected; | ||
}; | ||
expect.hasAssertions = (expected: any) => { | ||
utils.ensureNoExpected(expected, '.hasAssertions'); | ||
getState().isExpectingAssertions = true; | ||
}; | ||
expect.assertions = assertions; | ||
expect.hasAssertions = hasAssertions; | ||
expect.getState = getState; | ||
expect.setState = setState; | ||
expect.extractExpectedAssertionsErrors = extractExpectedAssertionsErrors; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unexpected that I was able to remove this 😛
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/cc @aaronabramov
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh.. i completely forgot about it 😀
i'm glad i didn't write a
TODO: remove after it lands
comment that dated early 2016 or something haha