Skip to content

Commit c934328

Browse files
committed
[ADD]🚀 AddCategory tests added
1 parent 0fc887c commit c934328

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import React from 'react';
2+
import { shallow } from 'enzyme';
3+
4+
import { AddCategory } from '../../components';
5+
6+
describe('Tests AddCategory component', () => {
7+
const setCategories = jest.fn();
8+
let wrapper = shallow(<AddCategory setCategories={setCategories} />);
9+
10+
beforeEach(() => {
11+
jest.clearAllMocks();
12+
wrapper = shallow(<AddCategory setCategories={setCategories} />);
13+
});
14+
15+
test('Should display correctly', () => {
16+
expect(wrapper).toMatchSnapshot();
17+
});
18+
19+
test('Should change the text box', () => {
20+
const input = wrapper.find('input');
21+
const value = 'Dragon Ball';
22+
23+
input.simulate('change', { target: { value } });
24+
const currentValue = wrapper.find('input').prop('value');
25+
26+
expect(currentValue).toBe(value);
27+
});
28+
29+
test('Should not call setCategories or setValue with the submit event', () => {
30+
wrapper.find('form').simulate('submit', { preventDefault(){} });
31+
expect(setCategories).not.toHaveBeenCalled();
32+
});
33+
34+
test('Should set value in "", setCategories must be called once and as a function', () => {
35+
const input = wrapper.find('input');
36+
const value = 'Dragon Ball';
37+
38+
input.simulate('change', { target: { value } });
39+
wrapper.find('form').simulate('submit', { preventDefault(){} });
40+
const currentValue = wrapper.find('input').prop('value');
41+
42+
expect(currentValue).toBe('');
43+
expect(setCategories).toHaveBeenCalled();
44+
expect(setCategories).toHaveBeenCalledTimes(1);
45+
//que sea evaluado con alguna funcion
46+
expect(setCategories).toHaveBeenCalledWith(expect.any(Function));
47+
});
48+
});
49+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Tests AddCategory component Should display correctly 1`] = `
4+
<form
5+
onSubmit={[Function]}
6+
>
7+
<input
8+
onChange={[Function]}
9+
placeholder="Add here..."
10+
type="text"
11+
value=""
12+
/>
13+
</form>
14+
`;

0 commit comments

Comments
 (0)