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
I would like to test this hook using react-hooks, but this hook needs the DOM to work. So I try a test using a wrapper:
describe('...',()=>{constdisplayName='Component';constComponent=()=><divdata-component-name={displayName}>test</div>;Component.displayName=displayName;constWrapper=({ children })=>(<><Component/>{children}</>);it('...',async()=>{const{ result, waitForValueToChange }=renderHook(()=>useDataAttributes(ComponentWithDataAttributes),{wrapper: Wrapper});awaitwaitForValueToChange(()=>result.current);expect(result.current).toEqual([{},expect.any(Function)]);});});
But when I check the document.body.children.length the value is 0 (no elements). I check the createTestHarness and understood that is not possible to test this way, but I want to confirm this.
I will test with @testing-library/react using a dummy component but is not too good to my case.
Thanks!
The text was updated successfully, but these errors were encountered:
What is your question:
I have a custom hook that checks the document using
querySelector
to get some information (like width, height, x, y, etc...) about a component.I would like to test this hook using react-hooks, but this hook needs the DOM to work. So I try a test using a wrapper:
But when I check the
document.body.children.length
the value is 0 (no elements). I check the createTestHarness and understood that is not possible to test this way, but I want to confirm this.I will test with
@testing-library/react
using a dummy component but is not too good to my case.Thanks!
The text was updated successfully, but these errors were encountered: