summaryrefslogtreecommitdiffstats
path: root/frontend/__tests__/EditUser.test.js
diff options
context:
space:
mode:
authorWes Bos <wesbos@gmail.com>2018-04-20 13:54:42 -0400
committerWes Bos <wesbos@gmail.com>2018-04-20 13:54:42 -0400
commit426aba70f5addfd3c6c1a972ced18395683feae9 (patch)
tree023a5291e9b088dab5c7ffc3f363b6509e22fb17 /frontend/__tests__/EditUser.test.js
parent13d263b7c088690b77d964f84fac454922b57ef8 (diff)
test
Diffstat (limited to 'frontend/__tests__/EditUser.test.js')
-rw-r--r--frontend/__tests__/EditUser.test.js55
1 files changed, 31 insertions, 24 deletions
diff --git a/frontend/__tests__/EditUser.test.js b/frontend/__tests__/EditUser.test.js
index 08dd6f6..f4aabfc 100644
--- a/frontend/__tests__/EditUser.test.js
+++ b/frontend/__tests__/EditUser.test.js
@@ -1,53 +1,60 @@
import React from 'react';
import { shallow } from 'enzyme';
import toJSON from 'enzyme-to-json';
-import { EditUser } from '../components/EditUser';
-
-const wait = amount => new Promise(resolve => setTimeout(resolve, amount));
+import EditUser from '../components/EditUser';
+import { mountWithApollo } from './mockMang';
+import wait from 'waait';
const currentUser = {
me: {
name: 'Wes Bos',
},
- refetch() {},
+ refetch() { },
};
describe('<EditUser/>', () => {
- it('renders', () => {
- const wrapper = shallow(<EditUser currentUser={currentUser} updateUser={() => {}} />);
- expect(toJSON(wrapper)).toMatchSnapshot();
+ 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 currentUser={{}} updateUser={() => {}} />);
+ const wrapper = shallow(<EditUser />);
expect(toJSON(wrapper)).toMatchSnapshot();
});
- it('displays changes', () => {
- const wrapper = shallow(<EditUser currentUser={currentUser} updateUser={() => {}} />);
+ 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', () => {
- const updateUserSpy = jest.fn();
- const wrapper = shallow(<EditUser currentUser={currentUser} updateUser={updateUserSpy} />);
+ 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.simulate('submit', { preventDefault() {} });
- expect(updateUserSpy).toHaveBeenCalledWith({ variables: { name: 'Scott' } });
+ wrapper.find('form').simulate('submit', { preventDefault() { } });
+ expect(mutation.client.mutate).toHaveBeenCalledWithVariables({ name: 'Scott' });
});
- it('refetches the current user after an update', async () => {
- const currentUserWithSpy = {
- me: { name: 'wes' },
- refetch: jest.fn(),
- };
- const wrapper = shallow(<EditUser currentUser={currentUserWithSpy} updateUser={() => {}} />);
- wrapper.simulate('submit', { preventDefault() {} });
- await wait(0);
- expect(currentUserWithSpy.refetch).toHaveBeenCalled();
+ it.only('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);
+ // wrapper.find('form').simulate('submit', { preventDefault() {} });
+ // expect(query.client.reFetchObservableQueries).toHaveBeenCalled();
});
});