summaryrefslogtreecommitdiffstats
path: root/frontend/__tests__/Signup.test.js
diff options
context:
space:
mode:
authorWes Bos <wesbos@gmail.com>2018-04-19 16:51:22 -0400
committerWes Bos <wesbos@gmail.com>2018-04-19 16:51:22 -0400
commit27f6237781bfe7fdc4ac1c7edaeee849434df92a (patch)
tree1822af24b1821616a81fb4fa9830ec6ef1a5f3bb /frontend/__tests__/Signup.test.js
parentaaae57b7978ffd0038ad560d6c9a4e8cf064cb0d (diff)
Tests for singup
Diffstat (limited to 'frontend/__tests__/Signup.test.js')
-rw-r--r--frontend/__tests__/Signup.test.js54
1 files changed, 54 insertions, 0 deletions
diff --git a/frontend/__tests__/Signup.test.js b/frontend/__tests__/Signup.test.js
new file mode 100644
index 0000000..f73c01c
--- /dev/null
+++ b/frontend/__tests__/Signup.test.js
@@ -0,0 +1,54 @@
+import React from 'react';
+import { mount } from 'enzyme';
+import toJSON from 'enzyme-to-json';
+import wait from 'waait';
+import Signup from '../components/Signup';
+import mountOptions from './mockMang';
+
+function type(wrapper, name, value) {
+ wrapper.find(`input[name="${name}"]`).simulate('change', {
+ target: {
+ name,
+ value,
+ },
+ });
+}
+
+describe('<Signup/>', () => {
+ beforeAll(() => {
+ // mock localStorage
+ global.localStorage = {
+ setItem: jest.fn(),
+ };
+ });
+
+ it('renders and matches snapshot', () => {
+ const wrapper = mount(<Signup />, mountOptions);
+ expect(toJSON(wrapper.find('form'))).toMatchSnapshot();
+ });
+
+ it('calls mutation with correct data', async () => {
+ const wrapper = mount(<Signup />, mountOptions);
+ const mutation = wrapper.find('Mutation').instance();
+ mutation.client.mutate = jest.fn().mockResolvedValue({
+ data: { signup: { token: 'omg123' } },
+ });
+
+ const expected = {
+ name: 'Randy',
+ email: 'Randy@randymail.net',
+ password: 'pupsrock',
+ };
+
+ type(wrapper, 'name', expected.name);
+ type(wrapper, 'email', expected.email);
+ type(wrapper, 'password', expected.password);
+
+ wrapper.simulate('submit');
+
+ expect(mutation.client.mutate).toHaveBeenCalled();
+ expect(mutation.client.mutate).toHaveBeenCalledWithVariables(expected);
+ await wait();
+ expect(localStorage.setItem).toHaveBeenCalledWith('token', 'omg123');
+ });
+});