Skip to content

Instantly share code, notes, and snippets.

@Karniej
Created February 8, 2018 11:38
Show Gist options
  • Save Karniej/ce177a3c9a2214b52f69bbf1ebdfbe2a to your computer and use it in GitHub Desktop.
Save Karniej/ce177a3c9a2214b52f69bbf1ebdfbe2a to your computer and use it in GitHub Desktop.
import 'react-native';
import React from 'react';
import NameScreen from '../NameScreen';
import configureStore from 'redux-mock-store';
import { shallow, configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
configure({ adapter: new Adapter() });
const mockStore = configureStore();
const initialState = {
form: {
fields: {},
values: {},
},
nav: {
index: 1,
routes: [],
},
};
describe('It ', () => {
test('should render correctly ', () => {
const props = {
navigation: jest.fn(),
onPress: jest.fn(),
};
const wrapper = shallow(<NameScreen {...props} />);
const render = wrapper.dive();
expect(render).toMatchSnapshot();
});
test('should have defined handleOnPress method ', () => {
const props = {
navigation: jest.fn(),
onPress: jest.fn(),
handleOnPress: jest.fn(),
};
const wrapper = shallow(<NameScreen {...props} />);
const instance = wrapper.instance();
expect(instance).toHaveProperty('handleOnPress');
expect(wrapper).toMatchSnapshot();
});
test('it should fire the handleOnPress method', () => {
const props = {
navigation: {
navigate: jest.fn(),
},
onPress: jest.fn(),
handleOnPress: jest.fn(),
};
const wrapper = shallow(<NameScreen {...props} />);
const render = wrapper.dive();
const spyOnHandle = jest.spyOn(wrapper.instance(), 'handleOnPress');
expect(render).toMatchSnapshot();
expect(render
.find('ReduxForm')
.props()
.handleOnPress());
expect(spyOnHandle).toHaveBeenCalled();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment