summaryrefslogtreecommitdiffstats
path: root/frontend/__tests__/AddToCart.test.js
blob: f049152b4725d8e3e0aab75982a65acea0738068 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import React from 'react';
import { shallow, mount } from 'enzyme';
import toJSON from 'enzyme-to-json';
import { AddToCart } from '../components/AddToCart';

const currentUser = {
  me: {},
  refetch() {},
};

describe('<AddtoCart/>', () => {
  it('renders and matches snapshot', () => {
    const wrapper = shallow(
      <AddToCart id="abc123" addToCart={() => {}} currentUser={currentUser} />
    );
    expect(toJSON(wrapper)).toMatchSnapshot();
  });

  it('adds an item to the cart', () => {
    const addToCart = jest.fn(() => Promise.resolve());
    const wrapper = shallow(
      <AddToCart id="abc123" addToCart={addToCart} currentUser={currentUser} />
    );
    wrapper.simulate('click');
    expect(addToCart).toHaveBeenCalled();
    expect(addToCart).toHaveBeenCalledWith({ variables: { id: 'abc123' } });
  });
});