Is CreateNodeMock supported?
See original GitHub issueIs CreateNodeMock supported?
I am not sure if I am using this wrong, but I am trying to mock a ref method. According to the API for the render function, it states:
function render(
component: React.Element<any>,
options?: {
/* A React Component that renders `component` as children */
wrapper?: React.ComponentType<any>,
/* You won't often use this, but it's helpful when testing refs */
createNodeMock: (element: React.Element<any>) => any,
}
): RenderResult {}
I am passing in the options like so (which I got from react-test-renderer)
const options = {
createNodeMock: (element) => {
console.log("element", element);
return {
takePictureAsync: takePictureMock
};
}
};
const {getByType, queryByTestId} = render(<Camera/>, options);
I never see the console.log print anything and I cannot find a test in render.test.js that covers the use of CreateNodeMock.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Testing React Components with React Test Renderer
createNodeMock function is called when Ref functions for DOMComponent is called. You can mock the Ref function through this option like this.
Read more >API | React Native Testing Library - Open Source
This options allows you to pass createNodeMock option to ... is done automatically if your test runner supports afterEach hook (like Jest, mocha,...
Read more >Test Renderer - React
createNodeMock accepts the current element and should return a mock ref object. This is useful when you test a component that relies on...
Read more >How to use the react-test-renderer.act function in react ... - Snyk
To help you get started, we've selected a few react-test-renderer.act examples, based on popular ways it is used in public projects.
Read more >Why is my renderer failing when using Material-UI using Jest ...
test('checked', () => { // Mock node - see https://reactjs.org/docs/test-renderer.html#ideas const createNodeMock = element => { return ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For those who will encounter this problem in the future.
Worked around it by
We pass it to react-test-renderer, but it doesn’t seem to work with react-native, at least the last time I tried to use it. Didn’t dig it too much though. We’d be glad if you helped us get it working 😃