reactTestInstance.toJSON() serializer
See original GitHub issueDo you want to request a feature or report a bug?
Feature
What is the current behavior?
ReactTestInstance
objects cannot currently be serialized to JSON, which prevents them from being used with Jest’s toMatchSnapshot
when wanting to capture a partial tree snapshot
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn’t have dependencies other than React. Paste the link to your JSFiddle (https://jsfiddle.net/Luktwrdm/) or CodeSandbox (https://codesandbox.io/s/new) example below:
What is the expected behavior?
const testRenderer = TestRenderer.create(<MyComponent />)
const testInstance = testRenderer.root
const subComponent = testInstance.findByType('SubComponent')
expect(subComponent).toMatchSnapshot()
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
The latest version. I’ve checked the source code, and it may just be a case of exporting this function: https://github.com/facebook/react/blob/master/packages/react-test-renderer/src/ReactTestRenderer.js#L79-L121
Issue Analytics
- State:
- Created 5 years ago
- Reactions:15
- Comments:10 (1 by maintainers)
Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please create a new issue with up-to-date information. Thank you!
@nhunzaker @gaearon Can we reopen this? It seems like a big blind spot.