From 06003b7a5f66f61bde6bb2fc9443c8cf3bc8bd9b Mon Sep 17 00:00:00 2001 From: Wes Bos Date: Fri, 4 May 2018 10:38:32 -0400 Subject: First apollo mutation test --- frontend/__tests__/RemoveFromCart.test.js | 38 ++++++++++++++++--------------- 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'frontend/__tests__/RemoveFromCart.test.js') diff --git a/frontend/__tests__/RemoveFromCart.test.js b/frontend/__tests__/RemoveFromCart.test.js index a640722..acf5755 100644 --- a/frontend/__tests__/RemoveFromCart.test.js +++ b/frontend/__tests__/RemoveFromCart.test.js @@ -27,25 +27,36 @@ const mocks = [ query: REMOVE_FROM_CART_MUTATION, variables: { id: 'abc123' }, }, - result: { data: { removeFromCart: { id: 'abc123' } } }, - }, - { - request: { query: CURRENT_USER_QUERY }, result: { data: { - me: { name: 'hi', cart: [], permissions: [], orders: [], id: 22, email: 'jame@apollo.com' }, + removeFromCart: { + __typename: 'CartItem', + id: 'abc123', + }, }, }, }, + // { + // request: { query: CURRENT_USER_QUERY }, + // result: { + // data: { + // me: { name: 'hi', cart: [], permissions: [], orders: [], id: 22, email: 'jame@apollo.com' }, + // }, + // }, + // }, ]; describe('', () => { it('renders and matches snapshot', () => { - const wrapper = mountWithApollo(); + const wrapper = mount( + + + + ); expect(toJSON(wrapper.find('button'))).toMatchSnapshot(); }); - fit('removes an item from the cart', async () => { + it('removes an item from the cart', async () => { // 1. Grab a copy of the current client let apolloClient; // const wrapper = mountWithApollo(); @@ -64,21 +75,12 @@ describe('', () => { // check if it worked const { me } = apolloClient.readQuery({ query: CURRENT_USER_QUERY }); expect(me.cart).toHaveLength(1); - // expect(me.cart[0].item.price).toBe(5000); + expect(me.cart[0].item.price).toBe(5000); // simulate a click, which will fire REMOVE_FROM_CART mock wrapper.find('button').simulate('click'); await wait(); const { me: me2 } = apolloClient.readQuery({ query: CURRENT_USER_QUERY }); - // console.log('----------'); - // console.log(me2); - // console.log('----------'); - // expect(me2.cart).toHaveLength(0); - // await wait(2); - // // the updated query from the mutation update - // await apollo.query({ query: CURRENT_USER_QUERY, fetchPolicy: 'cache-only' }) - - // // sync - // const user = apollo.readQuery({ query: CURRENT_USER_QUERY }) + expect(me2.cart).toHaveLength(0); }); }); -- cgit v1.3