diff options
Diffstat (limited to 'frontend/__tests__/AddToCart.test.js')
| -rw-r--r-- | frontend/__tests__/AddToCart.test.js | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/frontend/__tests__/AddToCart.test.js b/frontend/__tests__/AddToCart.test.js new file mode 100644 index 0000000..2285b3b --- /dev/null +++ b/frontend/__tests__/AddToCart.test.js @@ -0,0 +1,24 @@ +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' } }); + }); +}); |
