diff options
| author | Wes Bos <wesbos@gmail.com> | 2018-03-14 12:19:54 -0400 |
|---|---|---|
| committer | Wes Bos <wesbos@gmail.com> | 2018-03-14 12:19:54 -0400 |
| commit | 331da87bd53bc1fb79063d142764c75df9f32170 (patch) | |
| tree | d80aac98154a811fdf57b10e90ac0350fe14568e /frontend/__tests__/Item.test.js | |
| parent | 46a0ba30ef54a7e36206481a4f5b2bf1f9702fca (diff) | |
tests
Diffstat (limited to 'frontend/__tests__/Item.test.js')
| -rw-r--r-- | frontend/__tests__/Item.test.js | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/frontend/__tests__/Item.test.js b/frontend/__tests__/Item.test.js new file mode 100644 index 0000000..2990b1f --- /dev/null +++ b/frontend/__tests__/Item.test.js @@ -0,0 +1,31 @@ +/* eslint-env jest */ + +import React from 'react'; +import Enzyme, { shallow, mount } from 'enzyme'; +import toJSON from 'enzyme-to-json'; +import { ItemComponent } from '../components/Item'; + +const fakeItem = { + id: 'ABC123', + title: 'A Cool Item', + price: 5000, + description: 'This item is really cool!', + image: 'dog.jpg', + largeImage: 'largedog.jpg', +}; + +describe('<Item/>', () => { + it('Renders an item', () => { + const removeItem = jest.fn(); + const wrapper = shallow(<ItemComponent item={fakeItem} removeItem={removeItem} />); + expect(toJSON(wrapper)).toMatchSnapshot(); + }); + it('handles button clicks', async () => { + const removeItem = jest.fn(); + global.confirm = jest.fn().mockReturnValue(true); + const wrapper = shallow(<ItemComponent item={fakeItem} removeItem={removeItem} />); + wrapper.find('button').simulate('click'); + expect(removeItem).toHaveBeenCalled(); + expect(global.confirm).toHaveBeenCalled(); + }); +}); |
