From 072eca0e5038a7755ca9b2c94dfe1a0c3f110968 Mon Sep 17 00:00:00 2001 From: Wes Bos Date: Thu, 24 May 2018 15:19:21 -0400 Subject: colocate queries and components --- frontend/__tests__/AddToCart.test.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'frontend/__tests__/AddToCart.test.js') diff --git a/frontend/__tests__/AddToCart.test.js b/frontend/__tests__/AddToCart.test.js index 888ad68..fe15f3f 100644 --- a/frontend/__tests__/AddToCart.test.js +++ b/frontend/__tests__/AddToCart.test.js @@ -1,12 +1,12 @@ import React from 'react'; import { mount } from 'enzyme'; import toJSON from 'enzyme-to-json'; -import AddToCart from '../components/AddToCart'; import { ApolloConsumer } from 'react-apollo'; import { MockedProvider } from 'react-apollo/test-utils'; import wait from 'waait'; +import AddToCart, { ADD_TO_CART_MUTATION } from '../components/AddToCart'; import { fakeCartItem, fakeUser } from '../lib/testUtils'; -import { ADD_TO_CART_MUTATION, CURRENT_USER_QUERY } from '../queries/queries.graphql'; +import { CURRENT_USER_QUERY } from '../components/User'; const mocks = [ { @@ -34,12 +34,15 @@ const mocks = [ ]; describe('', () => { - it('renders and matches snapshot', () => { + it('renders and matches snapshot', async () => { const wrapper = mount( - + ); + await wait(); + wrapper.update(); + expect(toJSON(wrapper.find('button'))).toMatchSnapshot(); }); @@ -58,6 +61,8 @@ describe('', () => { ); await wait(); + wrapper.update(); + const { me } = apolloClient.readQuery({ query: CURRENT_USER_QUERY }); expect(me.cart).toHaveLength(0); @@ -72,12 +77,14 @@ describe('', () => { expect(me2.cart[0].quantity).toBe(1); }); - it('changes to adding when clicked', () => { + it('changes to adding when clicked', async () => { const wrapper = mount( ); + await wait(); + wrapper.update(); expect(wrapper.text()).toContain('🛒 Add To Cart'); wrapper.find('button').simulate('click'); expect(wrapper.text()).toContain('🛒 Adding To Cart'); -- cgit v1.3