Skip to content

Instantly share code, notes, and snippets.

@rcdexta
Created October 9, 2018 02:47
Show Gist options
  • Save rcdexta/89b24fca310d193e5e5dbde1cbf5b85c to your computer and use it in GitHub Desktop.
Save rcdexta/89b24fca310d193e5e5dbde1cbf5b85c to your computer and use it in GitHub Desktop.
TodoForm.test.js
test('TodoForm should add new item and call onAddItem callback prop', () => {
const addItem = jest.fn()
const {getByTestId} = render(<TodoForm onAddItem={addItem}/>)
let newItem = 'Get Milk'
fireEvent.change(getByTestId('newItemField'), {target: {value: newItem}})
getByTestId('addBtn').click()
expect(addItem).toBeCalledWith({newItemValue: newItem})
expect(addItem).toHaveBeenCalledTimes(1);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment