summaryrefslogtreecommitdiffstats
path: root/frontend/__tests__
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/__tests__')
-rw-r--r--frontend/__tests__/AddToCart.test.js2
-rw-r--r--frontend/__tests__/Cart.test.js26
-rw-r--r--frontend/__tests__/__snapshots__/Cart.test.js.snap32
-rw-r--r--frontend/__tests__/mockMang.js6
4 files changed, 45 insertions, 21 deletions
diff --git a/frontend/__tests__/AddToCart.test.js b/frontend/__tests__/AddToCart.test.js
index 92ad0ad..9b6a304 100644
--- a/frontend/__tests__/AddToCart.test.js
+++ b/frontend/__tests__/AddToCart.test.js
@@ -1,5 +1,5 @@
import React from 'react';
-import { shallow, mount } from 'enzyme';
+import { mount } from 'enzyme';
import toJSON from 'enzyme-to-json';
import AddToCart from '../components/AddToCart';
import mountOptions from './mockMang';
diff --git a/frontend/__tests__/Cart.test.js b/frontend/__tests__/Cart.test.js
index 2ee87a2..b62d0de 100644
--- a/frontend/__tests__/Cart.test.js
+++ b/frontend/__tests__/Cart.test.js
@@ -1,24 +1,16 @@
import React from 'react';
import { shallow, mount } from 'enzyme';
import toJSON from 'enzyme-to-json';
-import { Cart } from '../components/Cart';
-import { UIProvider } from '../components/UIContext';
-
-const cartItem = {
- item: { price: 5000 },
- quantity: 10,
-};
-
-const currentUser = {
- me: {
- cart: [cartItem, cartItem, cartItem],
- },
- refetch() {},
-};
+import mountOptions from './mockMang';
+import wait from 'waait';
+import Cart from '../components/Cart';
describe('<Cart/>', () => {
- it('renders', () => {
- const wrapper = shallow(<Cart currentUser={currentUser} />);
- console.log(wrapper.first());
+ it('renders', async () => {
+ const wrapper = mount(<Cart />, mountOptions);
+ await wait();
+ wrapper.update();
+ expect(toJSON(wrapper.find('header'))).toMatchSnapshot();
+ expect(wrapper.find('CartItem')).toHaveLength(2);
});
});
diff --git a/frontend/__tests__/__snapshots__/Cart.test.js.snap b/frontend/__tests__/__snapshots__/Cart.test.js.snap
index 65a7e7a..426bef2 100644
--- a/frontend/__tests__/__snapshots__/Cart.test.js.snap
+++ b/frontend/__tests__/__snapshots__/Cart.test.js.snap
@@ -1,3 +1,33 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
-exports[`<Cart/> renders 1`] = `<[object Object] />`;
+exports[`<Cart/> renders 1`] = `
+<header>
+ <styled.button
+ onClick={[Function]}
+ title="close"
+ >
+ <button
+ className="sc-EHOje jytiuo"
+ onClick={[Function]}
+ title="close"
+ >
+ ×
+ </button>
+ </styled.button>
+ <styled.h3>
+ <h3
+ className="sc-ifAKCX imryuh"
+ >
+ Miss Tillman Mitchell
+ 's Cart.
+ </h3>
+ </styled.h3>
+ <p>
+ You have
+ 2
+ item
+ s
+ in your cart.
+ </p>
+</header>
+`;
diff --git a/frontend/__tests__/mockMang.js b/frontend/__tests__/mockMang.js
index 7d65cd7..7f5403b 100644
--- a/frontend/__tests__/mockMang.js
+++ b/frontend/__tests__/mockMang.js
@@ -1,5 +1,6 @@
import { importSchema } from 'graphql-import';
-import GraphQLMock from 'graphql-mock';
+import { makeExecutableSchema } from 'graphql-tools';
+import MockClient from 'graphql-mock';
import casual from 'casual';
import PropTypes from 'prop-types';
@@ -13,6 +14,7 @@ const typeDefs = importSchema('../backend/src/schema.graphql');
const mocks = {
ID: () => casual.uuid,
+ Node: () => casual.uuid,
DateTime: () => new Date(1400000000000),
Int: () => casual.integer(400, 5500),
OrderItem: () => ({
@@ -36,7 +38,7 @@ const mocks = {
};
// Creates a mocked client
-const mocked = new GraphQLMock(typeDefs, mocks);
+const mocked = new MockClient(typeDefs, mocks);
const mountOptions = {
context: {