Skip to content

Instantly share code, notes, and snippets.

@wahengchang
Created February 1, 2018 09:46
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 wahengchang/a2ed3ac9d02f936fb78afa44818d353e to your computer and use it in GitHub Desktop.
Save wahengchang/a2ed3ac9d02f936fb78afa44818d353e to your computer and use it in GitHub Desktop.
unit-test-connected-component.js
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