Skip to content

Instantly share code, notes, and snippets.

@scottiedog45
Created December 15, 2017 04:24
Show Gist options
  • Save scottiedog45/00d7fc2331e1f468515390217939fb4f to your computer and use it in GitHub Desktop.
Save scottiedog45/00d7fc2331e1f468515390217939fb4f to your computer and use it in GitHub Desktop.
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