summaryrefslogtreecommitdiffstats
path: root/frontend/__tests__/RemoveFromCart.test.js
blob: 5f1a54a501f0c500a95f2595871a03a510a4bcf7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import React from 'react';
import toJSON from 'enzyme-to-json';
import RemoveFromCart from '../components/RemoveFromCart';
import { 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' });
  });
});