-
Notifications
You must be signed in to change notification settings - Fork 274
Show stack-trace for failed findBy or waitFor #547
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
Comments
Happy to accept a PR with this improvement! :) |
@thymikee has anyone looked into this already? |
None that I know of |
I spent almost a full day trying to add the stack-traces but I couldn't make it work properly. try {
let result: T;
//$FlowFixMe: `act` has incorrect flow typing
await act(async () => {
result = await waitForInternal(expectation, options);
});
//$FlowFixMe: either we have result or `waitFor` threw error
return result;
} catch (error) {
throw new ErrorWithStack(prepareErrorMessage(error), waitFor);
} When I run it in my project, I don't get any stack-trace, before or after that change. |
So you say that "I was able to show the correct stack-trace" and then "I don't get any stack-trace, before or after that change". I don't quite understand what you mean by that 😅. Have you made this change in node_modules of your project and it still didn't work? |
I used yalc to get the change in my project. |
Gotta fix it then! |
Did this every get fixed for waitFor? I'm using @testing-library/[email protected] (published after the fix for findBy) and multiple expects in a waitFor print as a failure at the waitFor line obscuring which one actually failed. i.e. where
I get
*** Update I tested on the latest version and it seems that fix has not been introduced. PRs still welcome to add this? |
Hmmm, that doesn't indeed sound ideal. In the perfect case you would be able to know what broke the However, I've had bad experiences with putting multiple |
ok thanks. If I have some time to tinker with it I will go for a PR. But otherwise I'll go with 1:1 waitFor:expect |
@kevinbror KCD also recommends using only single assertion for // ❌
await waitFor(() => {
expect(window.fetch).toHaveBeenCalledWith('foo')
expect(window.fetch).toHaveBeenCalledTimes(1)
})
// ✅
await waitFor(() => expect(window.fetch).toHaveBeenCalledWith('foo'))
expect(window.fetch).toHaveBeenCalledTimes(1)
|
Describe the Feature
Currently, if your test has a lot of
await findBy
, if one of them fails, it's hard to know which one from the error message.It'd be great if the error message would include the line of the
findBy
that fails, the same way it does forgetBy
with
findBy
:with
getBy
:Possible Implementations
I'd be happy to look into the code and see if I can provide a PR if nobody is currently working on this.
The text was updated successfully, but these errors were encountered: