|
| 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 | + |
0 commit comments