diff options
| author | Wes Bos <wesbos@gmail.com> | 2018-04-19 14:43:48 -0400 |
|---|---|---|
| committer | Wes Bos <wesbos@gmail.com> | 2018-04-19 14:43:48 -0400 |
| commit | aaae57b7978ffd0038ad560d6c9a4e8cf064cb0d (patch) | |
| tree | 4801d87e50d4c20817d443f9a7cc2092c82386f4 /frontend/__tests__ | |
| parent | e018f5482e550a49535f4df990d3bfc09128f5d8 (diff) | |
test test test
Diffstat (limited to 'frontend/__tests__')
| -rw-r--r-- | frontend/__tests__/AddToCart.test.js | 2 | ||||
| -rw-r--r-- | frontend/__tests__/Cart.test.js | 26 | ||||
| -rw-r--r-- | frontend/__tests__/__snapshots__/Cart.test.js.snap | 32 | ||||
| -rw-r--r-- | frontend/__tests__/mockMang.js | 6 |
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: { |
