question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

reactTestInstance.toJSON() serializer

See original GitHub issue

Do 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:closed
  • Created 5 years ago
  • Reactions:15
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
stale[bot]commented, Jan 17, 2020

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!

4reactions
kibiz0rcommented, Mar 15, 2022

@nhunzaker @gaearon Can we reopen this? It seems like a big blind spot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

react-test-renderer.ReactTestRenderer.toJSON JavaScript ...
Similar to `ReactDOM.render` but it doesn't require DOM and only renders a single level deep. ReactTestRenderer.toJSON · ReactTestInstance.props, ...
Read more >
Posting Form data as json to nested serializer from ReactJS
FormData was really causing me lots of problem My problem was the format i was using to post data to the server.
Read more >
Test Renderer - React
testRenderer.toJSON() ... Return an object representing the rendered tree. This tree only contains the platform-specific nodes like <div> or <View> and their ...
Read more >
Renderers - Django REST framework
For example the URL http://example.com/api/users_count.json might be an endpoint ... Note: When used with a view that makes use of a serializer the...
Read more >
Usage - Django REST framework JSON:API - Read the Docs
Serializers ¶. It is recommended to import the base serializer classes from this package rather than from vanilla DRF. For example,. from ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found