Skip to content

Instantly share code, notes, and snippets.

@linmic
Last active May 6, 2017 10:48
Show Gist options
  • Save linmic/43c27d14c84e36ab69ae0ac3b8dd9be3 to your computer and use it in GitHub Desktop.
Save linmic/43c27d14c84e36ab69ae0ac3b8dd9be3 to your computer and use it in GitHub Desktop.
jest.mock('../App');
import React from 'react';
import { Provider } from 'react-redux';
import { mount } from 'enzyme';
import App from '../App';
import AppContainer from '../AppContainer';
const storeFake = state => {
return {
default: jest.fn(),
subscribe: jest.fn(),
dispatch: jest.fn(),
getState: () => state,
};
};
describe('container <App />', () => {
let wrapper;
let component;
let container;
beforeEach(() => {
jest.resetAllMocks();
const store = storeFake({});
wrapper = mount(
<Provider store={store}>
<AppContainer />
</Provider>
);
container = wrapper.find(AppContainer);
component = container.find(App);
});
it('should render both the container and the component ', () => {
expect(container.length).toBeTruthy();
expect(component.length).toBeTruthy();
});
it('should map state to props', () => {
const expectedPropKeys = [
'users',
'auth',
'config',
];
expect(Object.keys(component.props())).toEqual(expect.arrayContaining(expectedPropKeys));
});
it('should map dispatch to props', () => {
const expectedPropKeys = ['load'];
expect(Object.keys(component.props())).toEqual(expect.arrayContaining(expectedPropKeys));
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment