react native jest snapshot 1

react native jest snapshot

// __tests__/Intro-test.js
import React from 'react';
import renderer from 'react-test-renderer';
import Intro from '../Intro';

test('renders correctly', () => {
  const tree = renderer.create().toJSON();

Here is what the above code is Doing:
1. We’re importing the React library, the renderer from react-test-renderer, and the component we want to test (Intro).
2. We’re creating a test that renders the component and creates a JSON file representation of it.
3. We’re using the toMatchSnapshot matcher to compare the rendered output to a previously stored snapshot.
4. We’re running the test by calling jest with the –watchAll flag.

Similar Posts