Reactjs.org: React Test Renderer: Add createRef() example for createNodeMock

Created on 4 Jul 2018  路  4Comments  路  Source: reactjs/reactjs.org

https://reactjs.org/docs/test-renderer.html#ideas demonstrates how to use createNodeMock to mock a callback ref. However, this example does not work for refs create with React.createRef(), because they use the current property. Could you extend the documentation please?

Most helpful comment

Need this badly, impossible to test components without it in TypeScript since we pretty much need to use React.createRef().

@Awem Did you come up with a solution?

All 4 comments

Need this badly, impossible to test components without it in TypeScript since we pretty much need to use React.createRef().

@Awem Did you come up with a solution?

Hi, is there any solution or alternative for this? Could be really useful.

I managed to test my component using Enzyme. Sadly i could not make it with react-test-renderer

Hi, I am actually not using createNodeMock anymore. Instead, I refactored the tested component to use the useRef hook. That works quite fine. I don't need mocks anymore.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

trungdq88 picture trungdq88  路  3Comments

OlegBrony picture OlegBrony  路  4Comments

grundmanise picture grundmanise  路  5Comments

tesseralis picture tesseralis  路  3Comments

gaearon picture gaearon  路  4Comments