Skip to content

Instantly share code, notes, and snippets.

@r3dm1ke
Created February 25, 2020 17:04
Show Gist options
  • Select an option

  • Save r3dm1ke/fdb6edb470227e92451cb9164683cb04 to your computer and use it in GitHub Desktop.

Select an option

Save r3dm1ke/fdb6edb470227e92451cb9164683cb04 to your computer and use it in GitHub Desktop.
import React from 'react';
import {render, cleanup, fireEvent} from 'react-native-testing-library';
import App from './App';
afterEach(cleanup);
describe('<App />', () => {
it('should match snapshot', () => {
const rendered = render(<App />).toJSON();
expect(rendered).toMatchSnapshot();
});
it('should set counter to 0', () => {
const rendered = render(<App />);
const counterComponent = rendered.getByTestId('counter');
expect(counterComponent.props.children).toContainEqual(0);
});
it('should increase counter by 1', () => {
const rendered = render(<App />);
const counterComponent = rendered.getByTestId('counter');
const buttonComponent = rendered. getByTestId('button');
fireEvent(buttonComponent, 'press');
expect(counterComponent.props.children).toContainEqual(1);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment