Skip to content

Instantly share code, notes, and snippets.

@muscaiu
Created February 1, 2019 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save muscaiu/387c91198da3327fa94186bfe623788a to your computer and use it in GitHub Desktop.
Save muscaiu/387c91198da3327fa94186bfe623788a to your computer and use it in GitHub Desktop.
import React from 'react';
import createItem from '../createItem';
import { connect } from 'react-redux';
import { selectItem } from '../../selectors/itemSelectors';
jest.resetModules();
jest.mock('react-redux');
const WrappedComponent = () => (<li />);
let mapStateToProps;
const initialState = {
entities: {
itemId: 1,
user: jest.fn()
}
};
describe('connect', () => {
beforeEach(() => {
connect.mockReturnValue(jest.fn);
createItem(WrappedComponent);
mapStateToProps = connect.mock.calls[0][0];
});
it('should call mapStateToProps()', () => {
createItem(WrappedComponent);
expect(connect).toHaveBeenCalled();
expect(mapStateToProps).toHaveProperty('name', 'mapStateToProps');
})
describe('mapStateToProps', () => {
it('should call selectUser', () => {
mapStateToProps(initialState);
expect(selectItem).toHaveBeenCalledWith(initialState.entities);
});
it('should return object', () => {
const { selectUser } = require('modules/user/selectors');
selectUser.mockReturnValue('myUser');
const results = mapStateToProps(initialState);
expect(results).toEqual({
user: 'myUser'
});
});
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment