From c9a2b488c83dcaae0a00d2177d3bfe1f185c28bf Mon Sep 17 00:00:00 2001 From: Wes Bos Date: Mon, 7 May 2018 16:54:27 -0400 Subject: TEST ESTSE TS ETSETST --- frontend/__tests__/ResetRequest.test.js | 102 +++++++++++++++++++++++++------- 1 file changed, 79 insertions(+), 23 deletions(-) (limited to 'frontend/__tests__/ResetRequest.test.js') diff --git a/frontend/__tests__/ResetRequest.test.js b/frontend/__tests__/ResetRequest.test.js index a08f3bc..c7d8012 100644 --- a/frontend/__tests__/ResetRequest.test.js +++ b/frontend/__tests__/ResetRequest.test.js @@ -2,37 +2,93 @@ import React from 'react'; import { mount } from 'enzyme'; import toJSON from 'enzyme-to-json'; import ResetRequest from '../components/ResetRequest'; -import mountOptions from '../lib/testUtils'; +import { MockedProvider } from 'react-apollo/test-utils'; +import wait from 'waait'; +import { fakeItem } from '../lib/testUtils'; +import { REQUEST_RESET_MUTATION, RESET_MUTATION } from '../queries/queries'; + +const mocks = [ + { + request: { + query: REQUEST_RESET_MUTATION, + variables: { + email: 'wesbos@gmail.com', + }, + }, + result: { + data: { + requestReset: { id: 'abc123', __typename: 'User' }, + }, + }, + }, +]; describe('', () => { it('renders and matches snapshot', async () => { - const wrapper = mount(, mountOptions); - const Form = wrapper.find("Form[data-test='ResetRequest']"); - expect(toJSON(Form)).toMatchSnapshot(); + const wrapper = mount( + + + + ); + const form = wrapper.find("form[data-test='ResetRequest']"); + expect(toJSON(form)).toMatchSnapshot(); }); it('calls the mutation', async () => { - const wrapper = mount(, mountOptions); - const mutation = wrapper.find('Mutation').instance(); - const input = wrapper.find('input[name="email"]'); - input.simulate('change', { target: { name: 'email', value: 'wesbos@gmail.com' } }); - // Create a spy function on mutate - mutation.client.mutate = jest.fn(); - // mutation.forceUpdate(); - wrapper.find('Form').simulate('submit'); - - expect(mutation.client.mutate).toBeCalledWithVariables({ email: 'wesbos@gmail.comx' }); - - expect(toJSON(wrapper)).toMatchSnapshot(); + const wrapper = mount( + + + + ); + + wrapper.find('input').simulate('change', { + target: { value: 'wesbos@gmail.com' }, + }); + + // submit the form + wrapper.find('form').simulate('submit'); + + await wait(); + wrapper.update(); + expect(wrapper.find('p').text()).toContain('Success! Check Your Email!'); }); - it('renders errors', () => { - const wrapper = mount(, mountOptions); - const mutation = wrapper.find('Mutation').instance(); - mutation.setState({ error: { message: 'Shit!' } }); + xit('displays an error', async () => { + const errorMocks = [ + { + request: { + query: REQUEST_RESET_MUTATION, + variables: { + email: 'wesbos@gmail.com', + }, + }, + error: { + message: 'Shit', + }, + }, + ]; + const wrapper = mount( + + + + ); + + wrapper.find('input').simulate('change', { + target: { value: 'wesbos@gmail.com' }, + }); + + try { + wrapper.find('form').simulate('submit'); + await wait(); + } catch (e) { + console.log(e); + } + // expect(async () => { + // }).toThrow(); + + // wrapper.find('form').simulate('submit'); wrapper.update(); - const error = wrapper.find('DisplayError'); - expect(error).toHaveLength(1); - expect(toJSON(error)).toMatchSnapshot(); + console.log(wrapper.debug()); + // expect(wrapper.find('p').text()).toContain('Success! Check Your Email!'); }); }); -- cgit v1.3