summaryrefslogtreecommitdiffstats
path: root/frontend/__tests__/RemoveFromCart.test.js
blob: 9cdde5e0e9636a99f34ddc7356276d362d677846 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import React from 'react';
import { shallow, mount } from 'enzyme';
import toJSON from 'enzyme-to-json';
import { ApolloProvider } from 'react-apollo';
import RemoveFromCart from '../components/RemoveFromCart';
import mountOptions, { mocked, mountWithApollo } from './mockMang';

describe('<RemoveFromCart/>', () => {
  it('renders and matches snapshot', () => {
    const wrapper = mountWithApollo(<RemoveFromCart id="123" />);
    expect(toJSON(wrapper.find('button'))).toMatchSnapshot();
  });

  it('runs the mutation with correct variables', () => {
    const wrapper = mountWithApollo(<RemoveFromCart id="abc123" />);
    const mutation = wrapper.find('Mutation').instance();
    mutation.client.mutate = jest.fn().mockResolvedValue({ removeFromCart: { id: 'abc123' } });
    wrapper.find('button').simulate('click');
    expect(mutation.client.mutate).toHaveBeenCalled();
    expect(mutation.client.mutate).toHaveBeenCalledWithVariables({ id: 'abc123' });
  });
});