You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
error-component.tsx (just as an example, I know the return is unreachable):
exportconstErrorComponent=()=>{// This logs four times, but it should log only once?console.log('test error in component');// When debugging this during a test, the debugger wil stop here five times. But we expect that it stops only once?thrownewError('test error in component');return<p>This is an error test component, which will throw an error</p>;};
error-component.spec.tsx:
import{render}from'@testing-library/react';import{ErrorComponent}from'./error-component';it('should throw',()=>{expect(()=>render(<ErrorComponent/>)).toThrow('test error in component');});
What you did:
I was trying to test if a specific error was thrown in a component and used the render function from @testing-library/react.
What happened:
When debugging the component that is called in the render function, I found out that it seems to load 4/5 times.
Without throwing an error in the component that is being rendered, the component only loads once.
When calling the component that throws an error without the render function, the component only loads once.
Having said that, I'm not sure this is related to our implementation as we're not doing something special there, just calling root.render. I'll have to look into it though I'm not sure I'll have time to do it soon.
Relevant code or config:
https://github.com/R-J-dev/example-error-render-issue/blob/main/src/test-error/error-component.tsx
error-component.tsx (just as an example, I know the return is unreachable):
error-component.spec.tsx:
What you did:
I was trying to test if a specific error was thrown in a component and used the render function from @testing-library/react.
What happened:
When debugging the component that is called in the render function, I found out that it seems to load 4/5 times.
Without throwing an error in the component that is being rendered, the component only loads once.
When calling the component that throws an error without the render function, the component only loads once.
Reproduction:
Reproduction repo can be found here: https://github.com/R-J-dev/example-error-render-issue/tree/main
It's a new setup created with:
npx create-nx-workspace@latest
(https://nx.dev/getting-started/intro)The test: https://github.com/R-J-dev/example-error-render-issue/blob/main/src/test-error/error-component.spec.tsx
The component: https://github.com/R-J-dev/example-error-render-issue/blob/main/src/test-error/error-component.tsx
Problem description:
Not sure if this is normal behavior, but for me it's unexpected behavior and couldn't find why this is happening.
Also:
Suggested solution:
It looks like that the problem is in the render function from @testing-library/react, but besides from that I have no clue yet.
The text was updated successfully, but these errors were encountered: