Created
February 1, 2018 09:46
-
-
Save wahengchang/a2ed3ac9d02f936fb78afa44818d353e to your computer and use it in GitHub Desktop.
unit-test-connected-component.js
This file contains hidden or 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 { connect } from 'react-redux' | |
import { mount, shallow } from 'enzyme' | |
import ToastList from '../../../src/components/common/ToastList' | |
jest.mock('../../../src/components/common/ToastList/ToastItem/index.js', () => | |
(props) => <mock-toast-item id={props.id}> | |
{props.msg} | |
</mock-toast-item> | |
) | |
const shallowWithState = (Component, state) => { | |
const context = { | |
store: { | |
getState: () => state, | |
subscribe: () => ({}), | |
dispatch: () => ({}) | |
} | |
} | |
return mount(Component, { context}) | |
} | |
describe('TextSlider', () => { | |
it('should return 2 toastItem when given 2 elements in toastlist', () => { | |
const msg = 'mockMsg' | |
const toastlist = [{id:0, msg}, {id:1, msg}] | |
const wrapper = shallowWithState(<ToastList/>, {toastlist}) | |
expect(wrapper.find('mock-toast-item').length).toEqual(2) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment