blob: 345b365ba9aaff90bd72f4da8fb4b8e5f962327f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
import { mount } from 'enzyme';
import wait from 'waait';
import toJSON from 'enzyme-to-json';
import { MockedProvider } from 'react-apollo/test-utils';
import RequestReset, { REQUEST_RESET_MUTATION } from '../components/RequestReset';
const mocks = [
{
request: {
query: REQUEST_RESET_MUTATION,
variables: { email: 'wesbos@gmail.com' },
},
result: {
data: { requestReset: { message: 'success', __typename: 'Message' } },
},
},
];
describe('<RequestReset/>', () => {
it('renders and matches snapshot', async () => {
const wrapper = mount(
<MockedProvider>
<RequestReset />
</MockedProvider>
);
const form = wrapper.find('form[data-test="form"]');
expect(toJSON(form)).toMatchSnapshot();
});
it('calls the mutation', async () => {
const wrapper = mount(
<MockedProvider mocks={mocks}>
<RequestReset />
</MockedProvider>
);
// simulate typing an email
wrapper
.find('input')
.simulate('change', { target: { name: 'email', 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 for a reset link!');
});
});
|