blob: 2990b1f767740447ee7a4529fa07eff538ca4257 (
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
29
30
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();
});
});
|