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
react-test-renderer version (if applicable): 17.0.2
node version: 15.13.10
npm (or yarn) version: 1.22.10(yarn)
Relevant code or config:
useCounter.ts
importReact,{useState,useContext,useCallback}from'react';constCounterStepContext=React.createContext(1);exportconstCounterStepProvider=({ step, children }: any)=>(<CounterStepContext.Providervalue={step}>{children}</CounterStepContext.Provider>);exportfunctionuseCounter(initialValue=0){const[count,setCount]=useState(initialValue);conststep=useContext(CounterStepContext);constincrement=useCallback(()=>setCount((x)=>x+step),[step]);constreset=useCallback(()=>setCount(initialValue),[initialValue]);return{ count, increment, reset };}
useCounter.test.ts
import{renderHook,act}from'@testing-library/react-hooks';import{useCounter,CounterStepProvider}from'./useCounter';test('should use custom step when incrementing',()=>{const{ result }=renderHook(()=>useCounter(),{wrapper: ({ children })=>(<CounterStepProviderstep={2}>{children}</CounterStepProvider>),});act(()=>{result.current.increment();});expect(result.current.count).toBe(2);});
What you did:
I just follow the code in react testing library hooks docs.
and yarn test
What happened:
when yarn test, I got this error
FAILsrc/test/useCounter.test.tsx✕shouldusecustomstepwhenincrementing(5ms)●shouldusecustomstepwhenincrementingObjectsarenotvalidasaReactchild(found: objectwithkeys{type, props, key, ref, __k,__, __b, __e, __d, __c, __h, constructor, __v, __source, __self}).Ifyoumeanttorenderacollectionofchildren,useanarrayinstead.3|4|test('should use custom step when incrementing',()=>{>5|const{ result }=renderHook(()=>useCounter(),{|^6|wrapper: ({ children })=>(7|<CounterStepProviderstep={2}>{children}</CounterStepProvider>8|),atthrowOnInvalidObjectType(node_modules/react-test-renderer/cjs/react-test-renderer.development.js:4537:15)atreconcileChildFibers(node_modules/react-test-renderer/cjs/react-test-renderer.development.js:5439:7)atreconcileChildren(node_modules/react-test-renderer/cjs/react-test-renderer.development.js:7984:28)atmountIndeterminateComponent(node_modules/react-test-renderer/cjs/react-test-renderer.development.js:8810:5)atbeginWork(node_modules/react-test-renderer/cjs/react-test-renderer.development.js:9966:16)atperformUnitOfWork(node_modules/react-test-renderer/cjs/react-test-renderer.development.js:13800:12)atworkLoopSync(node_modules/react-test-renderer/cjs/react-test-renderer.development.js:13728:5)atrenderRootSync(node_modules/react-test-renderer/cjs/react-test-renderer.development.js:13691:7)atperformSyncWorkOnRoot(node_modules/react-test-renderer/cjs/react-test-renderer.development.js:13404:18)atnode_modules/react-test-renderer/cjs/react-test-renderer.development.js:2537:26atunstable_runWithPriority(node_modules/scheduler/cjs/scheduler.development.js:468:12)atrunWithPriority(node_modules/react-test-renderer/cjs/react-test-renderer.development.js:2486:10)atflushSyncCallbackQueueImpl(node_modules/react-test-renderer/cjs/react-test-renderer.development.js:2532:9)atflushSyncCallbackQueue(node_modules/react-test-renderer/cjs/react-test-renderer.development.js:2519:3)atbatchedUpdates(node_modules/react-test-renderer/cjs/react-test-renderer.development.js:13459:7)atact(node_modules/react-test-renderer/cjs/react-test-renderer.development.js:15280:14)atrender(node_modules/@testing-library/react-hooks/lib/native/pure.js:73:34)atrenderHook(node_modules/@testing-library/react-hooks/lib/core/index.js:114:5)atObject.<anonymous>(src/test/useCounter.test.tsx:5:22)TestSuites: 1failed,1totalTests: 1failed,1totalSnapshots: 0totalTime: 0.337s,estimated1sRanalltestsuites.
Reproduction:
Problem description:
I could not move forward anymore.
Suggested solution:
The text was updated successfully, but these errors were encountered:
@mpeyper Thanks for looking into it. Has there been any follow up? The above example is a copy of whats currently on the official testing-library example. I'm running into the same issue with the following versioning:
Hi @rharrigan-sugarcrm, honestly probably not and if I did look then I don’t remember.
In your case though, if you are using React 18 you should be using renderHook from @testing-library/react instead of @testing-library/react/hooks now. Let them know if you are still having issues after you migrate to the new API.
react-hooks-testing-library
version: 7.0.1react
version: 17.0.2react-dom
version (if applicable): 17.0.2react-test-renderer
version (if applicable): 17.0.2node
version: 15.13.10npm
(oryarn
) version: 1.22.10(yarn)Relevant code or config:
useCounter.ts
useCounter.test.ts
What you did:
I just follow the code in react testing library hooks docs.
and yarn test
What happened:
when yarn test, I got this error
Reproduction:
Problem description:
I could not move forward anymore.
Suggested solution:
The text was updated successfully, but these errors were encountered: