Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save takahirohonda/fa1fc3909600966e23a942ec5136b3cf to your computer and use it in GitHub Desktop.
Save takahirohonda/fa1fc3909600966e23a942ec5136b3cf to your computer and use it in GitHub Desktop.
setting-up-unit-tests-for-react-with-mocha-jsdom-and-enzyme
import React from 'react'
import { expect } from 'chai'
import { shallow, mount } from 'enzyme'
import sinon from 'sinon'
import Form from '../Form'
import initialState from '../../reducers/initialState'
describe('<Form />', () => {
let state;
let spySubmitHandler;
beforeEach(() => {
state = initialState.information;
spySubmitHandler = sinon.spy();
});
it.only('should fire onSubmit function', () => {
const wrapper = mount(
<Form
information={state}
onSubmitHandler={spySubmitHandler}
/>);
wrapper.find('button').simulate('click');
sinon.assert.calledOnce(spySubmitHandler)
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment