Skip to content

Instantly share code, notes, and snippets.

@CodingItWrong
Created January 4, 2019 02:40
Show Gist options
  • Select an option

  • Save CodingItWrong/5ed2255fdf2ca9e0900e1ba14fbaee9f to your computer and use it in GitHub Desktop.

Select an option

Save CodingItWrong/5ed2255fdf2ca9e0900e1ba14fbaee9f to your computer and use it in GitHub Desktop.
describe('clicking send', () => {
const messageText = 'Hello world';
+ let sendHandler;
let getByTestId;
beforeEach(() => {
+ sendHandler = jest.fn();
- ({ getByTestId } = render(<NewMessageForm />));
+ ({ getByTestId } = render(<NewMessageForm onSend={sendHandler} />));
fireEvent.changeText(getByTestId('messageText'), messageText);
fireEvent.press(getByTestId('sendButton'));
...
it('clears the message field', () => {
expect(getByTestId('messageText').props.value).toEqual('');
});
+
+ it('calls the send handler', () => {
+ expect(sendHandler).toHaveBeenCalledWith(messageText);
+ });
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment