Skip to content

Instantly share code, notes, and snippets.

@adrian-afergon
Created August 16, 2018 15:42
Show Gist options
  • Save adrian-afergon/4b8560d2d4bee5db0df4db28f3c358b3 to your computer and use it in GitHub Desktop.
Save adrian-afergon/4b8560d2d4bee5db0df4db28f3c358b3 to your computer and use it in GitHub Desktop.
Add mock to test App.test.js
import React from 'react';
import App from './App';
import renderer from 'react-test-renderer';
import Adapter from 'enzyme-adapter-react-16'
import { shallow, configure } from 'enzyme';
configure({ adapter: new Adapter() });
it('renders without crashing', () => {
const rendered = renderer.create(<App />).toJSON();
expect(rendered).toBeTruthy();
});
describe ('test', () => {
it('shallow', () => {
const element = shallow(<App/>);
expect(element.exists()).toBeTruthy();
});
it('should find button', () => {
const element = shallow(<App />);
const aButton = element.find('Button');
expect(aButton.exists()).toBeTruthy();
});
it('should click a button', () => {
const aEvent = jest.fn();
const element = shallow(<App myMethod={aEvent}/>);
const aButton = element.find('Button');
aButton.get(0).props.onPress();
expect(aEvent).toHaveBeenCalled();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment