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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
import React from 'react';
import { shallow } from 'enzyme';
import toJSON from 'enzyme-to-json';
import EditUser from '../components/EditUser';
import { mountWithApollo } from './mockMang';
import wait from 'waait';
const currentUser = {
me: {
name: 'Wes Bos',
},
refetch() {},
};
describe('<EditUser/>', () => {
it('renders', async () => {
const { wrapper, component } = mountWithApollo(<EditUser />);
await wait();
wrapper.update();
expect(toJSON(wrapper.find('Form'))).toMatchSnapshot();
});
it('asks you to log in when you arent logged in', () => {
const wrapper = shallow(<EditUser />);
expect(toJSON(wrapper)).toMatchSnapshot();
});
it('displays changes', async () => {
const { wrapper } = mountWithApollo(<EditUser />);
await wait();
wrapper.update();
const nameInput = wrapper.find('[name="name"]');
nameInput.simulate('change', { target: { name: 'name', value: 'Scott' } });
const diff = wrapper.find('pre[data-test="change"]');
expect(diff.text()).toBe('{"name":"Scott"}');
});
it('calls update user when form is submitted', async () => {
const { wrapper } = mountWithApollo(<EditUser />);
await wait();
wrapper.update();
const mutation = wrapper.find('Mutation').instance();
mutation.client.mutate = jest.fn();
const nameInput = wrapper.find('[name="name"]');
nameInput.simulate('change', { target: { name: 'name', value: 'Scott' } });
wrapper.find('form').simulate('submit', { preventDefault() {} });
expect(mutation.client.mutate).toHaveBeenCalledWithVariables({ name: 'Scott' });
});
it('refetches the current user after an update', async () => {
const { wrapper } = mountWithApollo(<EditUser />);
await wait();
wrapper.update();
const query = wrapper.find('Query').instance();
const mutation = wrapper.find('Mutation').instance();
console.log(mutation.props.mutation);
expect('wes').toBe('finished with this one');
// wrapper.find('form').simulate('submit', { preventDefault() {} });
// expect(query.client.reFetchObservableQueries).toHaveBeenCalled();
});
});
|