Skip to content

Instantly share code, notes, and snippets.

@qswitcher
Last active July 30, 2018 02:58
Show Gist options
  • Save qswitcher/05fec8415100210f5d0b88699e97d788 to your computer and use it in GitHub Desktop.
Save qswitcher/05fec8415100210f5d0b88699e97d788 to your computer and use it in GitHub Desktop.
import React from 'react';
import { mount } from 'enzyme';
import App from '../../App';
test('entering a todo in form adds a todo', async () => {
wrapper = mount(<App />);
// enter todo text in textbox
wrapper.find('.TodoForm-input').instance().value = 'My new todo';
// click Add
wrapper.find('.TodoForm-button').simulate('click');
// wait for Todo to show up
await wait(wrapper, w =>
w
.find('.TodoItem')
.at(3)
.exists()
);
// make sure form is cleared
expect(wrapper.find('.TodoForm-input').instance().value).toEqual('');
// make sure todo was added
const newText = wrapper
.find('.TodoItem')
.at(3)
.find('.TodoItem-text')
.text();
expect(newText).toEqual('My new todo');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment