-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.js
38 lines (36 loc) · 1.54 KB
/
index.test.js
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
32
33
34
35
36
37
38
import Card from './index';
import React from 'react';
import { shallow } from 'enzyme';
const img = require('../../../../images/bystander.jpg');
describe('Card', () => {
let mockCard = { type: 'bystander' };
let mockFn = jest.fn();
let wrapper = shallow(<Card card={mockCard} sendGuess={mockFn} />);
it('should matchsnapshot', () => {
wrapper = shallow(<Card card={{ type: 'bystander' }} sendGuess={mockFn} />);
wrapper.setState({ flipped: false });
expect(wrapper).toMatchSnapshot();
});
it('should matchsnapshot', () => {
let wrapper = shallow(<Card card={mockCard} isActive={false} />);
wrapper.setState({ flipped: true });
expect(wrapper).toMatchSnapshot();
});
it('sendGuess should be called on click of the card', () => {
wrapper = shallow(<Card sendGuess={mockFn} isActive={true} card={{ type: false }} />);
jest.spyOn(wrapper.instance(), 'handleClick');
let mockEvent = { target: { value: '', name: 'title' }, currentTarget: {value: 3} };
wrapper.find('article').simulate('click', mockEvent);
expect(mockFn).toHaveBeenCalled();
});
it('should send an id when is Active is true and card.type is false', () => {
let mockCard = { type: false };
wrapper = shallow(<Card card={mockCard} sendGuess={mockFn} isActive={true} />);
expect(mockFn).toHaveBeenCalled();
});
it('should not send an id when is Active is false and card.type is true', () => {
let mockCard = { type: 'bystander' };
wrapper = shallow(<Card card={mockCard} sendGuess={mockFn} isActive={false} />);
expect(mockFn).toHaveBeenCalled();
});
});