Created
February 1, 2019 16:33
-
-
Save muscaiu/387c91198da3327fa94186bfe623788a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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