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
import{useEffect,useState}from'react';constuseHook=()=>{const[value,setValue]=useState('default');useEffect(()=>{setValue(31337);},[]);//throw new Error(value); // logs 'default' - how can I test this?returnvalue;};exportdefaultuseHook;
useHook.test.js
import{renderHook}from'@testing-library/react';importuseHookfrom"./useHook";describe('useHook',()=>{it('should return 31337',()=>{// Actconst{ result }=renderHook(()=>useHook());// Assertexpect(result.all[0]).toBe('default');// fails, all doesn't exist for some reasonexpect(result.current).toBe(31337);});});
What you did:
Hi folks, I'm trying to test a hook that causes a bug for us. I can fix the bug by changing the initial useState call but I really want to add a test to stop this regressing.
I can't get it to test the return value of 'default' at all. result.all is undefined, the only thing I see is result.current, which is 31337 - but if I uncomment the throw you can see that it does return 'default' at first.
How can I test this please?
I looked at #716 which looks like the same bug, but the solution there doesn't apply because I can't see the .all property.
The text was updated successfully, but these errors were encountered:
react-hooks-testing-library
version: ??react
version: 19react-dom
version: 19node
version: 20Relevant code or config:
What you did:
Hi folks, I'm trying to test a hook that causes a bug for us. I can fix the bug by changing the initial useState call but I really want to add a test to stop this regressing.
I can't get it to test the return value of 'default' at all. result.all is undefined, the only thing I see is result.current, which is 31337 - but if I uncomment the throw you can see that it does return 'default' at first.
How can I test this please?
I looked at #716 which looks like the same bug, but the solution there doesn't apply because I can't see the
.all
property.The text was updated successfully, but these errors were encountered: