From bd45d4c7aac6d1c6b054185058a96b2e01669828 Mon Sep 17 00:00:00 2001 From: Wes Bos Date: Wed, 14 Mar 2018 21:00:08 -0400 Subject: tests --- frontend/__tests__/AddToCart.test.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 frontend/__tests__/AddToCart.test.js (limited to 'frontend/__tests__/AddToCart.test.js') 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('', () => { + it('renders and matches snapshot', () => { + const wrapper = shallow( {}} currentUser={currentUser} />); + expect(toJSON(wrapper)).toMatchSnapshot(); + }); + + it('adds an item to the cart', () => { + const addToCart = jest.fn(() => Promise.resolve()); + const wrapper = shallow(); + wrapper.simulate('click'); + expect(addToCart).toHaveBeenCalled(); + expect(addToCart).toHaveBeenCalledWith({ variables: { id: 'abc123' } }); + }); +}); -- cgit v1.3