diff options
| author | Wes Bos <wesbos@gmail.com> | 2018-03-14 21:00:08 -0400 |
|---|---|---|
| committer | Wes Bos <wesbos@gmail.com> | 2018-03-14 21:00:08 -0400 |
| commit | bd45d4c7aac6d1c6b054185058a96b2e01669828 (patch) | |
| tree | aeee19f26cc846496213822b6b28c9aa223bc6d1 /frontend/__tests__/AddToCart.test.js | |
| parent | 7c760dd4d1e27180222d3d524949216e5b65194a (diff) | |
tests
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' } }); + }); +}); |
