Created
December 15, 2017 04:24
-
-
Save scottiedog45/00d7fc2331e1f468515390217939fb4f 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 { shallow, mount } from 'enzyme'; | |
import GuessForm from './guess-form'; | |
describe('<GuessForm />', () => { | |
it('Renders without crashing', () => { | |
shallow(<GuessForm />); | |
}); | |
it('Should fire the onMakeGuess callback when the form is submitted', () => { | |
const callback = jest.fn(); | |
const wrapper = mount(<GuessForm onMakeGuess={callback} />); | |
const value = 10; | |
wrapper.find('input[type="number"]').instance().value = value; | |
wrapper.simulate('submit'); | |
expect(callback).toHaveBeenCalledWith(value.toString()); | |
}); | |
it('Should reset the input when the form is submitted', () => { | |
const wrapper = mount(<GuessForm />); | |
const input = wrapper.find('input[type="number"]'); | |
input.instance().value = 10; | |
wrapper.simulate('submit'); | |
expect(input.instance().value).toEqual(''); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment