-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
74 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,23 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { render, fireEvent, screen, getByTestId} from '@testing-library/react'; | ||
import { shallow, mount } from 'enzyme'; | ||
import Form, {validate} from './Form.jsx'; | ||
|
||
describe('<Form />', () => { | ||
describe('App', () => { | ||
let wrapper; | ||
const setState = jest.fn(); | ||
const useStateSpy = jest.spyOn(React, 'useState') | ||
useStateSpy.mockImplementation((init) => [init, setState]); | ||
|
||
beforeEach(() => { | ||
wrapper = shallow(<Form />); | ||
wrapper = mount(<Form />); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
it('El form deberia cambiar de estado cuando escriban en el input de username', () => { | ||
wrapper.find('input[name="username"]').simulate('change', {target: {name: 'username', value: 'NewUsr'}}); | ||
const ele = wrapper.find('input[name="username"]'); | ||
expect(ele.prop('value')).toEqual('NewUsr'); | ||
}); | ||
|
||
describe('Estados: ', () => { | ||
it('El form deberia cambiar de estado cuando escriban en el input de username', () => { | ||
wrapper.find('input[name="username"]').simulate('change', {target: {name: 'username', value: 'My new value'}}); | ||
expect(setState).toHaveBeenCalledWith({"username": "My new value", "password": ""}); | ||
}); | ||
it('El form deberia cambiar de estado cuando escriban en el input de password', () => { | ||
wrapper.find('input[name="username"]').simulate('change', {target: {name: 'password', value: 'My new value'}}); | ||
expect(setState).toHaveBeenCalledWith({"username": "", "password": "My new value"}); | ||
}); | ||
it('El form deberia cambiar de estado cuando escriban en el input de password', () => { | ||
wrapper.find('input[name="password"]').simulate('change', {target: {name: 'password', value: 'NewPsw'}}); | ||
const ele = wrapper.find('input[name="password"]'); | ||
expect(ele.prop('value')).toEqual("NewPsw"); | ||
}); | ||
|
||
describe('Validacion: ', () => { | ||
it('validate debe devolver un objeto con un error si el usarname no es un email valido:', () => { | ||
expect(validate({ | ||
|
@@ -56,4 +46,56 @@ describe('<Form />', () => { | |
}); | ||
}); | ||
|
||
|
||
// describe('<Form />', () => { | ||
// let wrapper; | ||
// const setState = jest.fn(); | ||
// const useStateSpy = jest.spyOn(React, 'useState') | ||
// useStateSpy.mockImplementation((init) => [init, setState]); | ||
// | ||
// beforeEach(() => { | ||
// wrapper = shallow(<Form />); | ||
// }); | ||
// | ||
// afterEach(() => { | ||
// jest.clearAllMocks(); | ||
// }); | ||
// | ||
// describe('Estados: ', () => { | ||
// it('El form deberia cambiar de estado cuando escriban en el input de username', () => { | ||
// wrapper.find('input[name="username"]').simulate('change', {target: {name: 'username', value: 'My new value'}}); | ||
// console.log(wrapper.find('input[name="username"]')); | ||
// expect(setState).toHaveBeenCalledWith({"username": "My new value", "password": ""}); | ||
// }); | ||
// it('El form deberia cambiar de estado cuando escriban en el input de password', () => { | ||
// wrapper.find('input[name="username"]').simulate('change', {target: {name: 'password', value: 'My new value'}}); | ||
// expect(setState).toHaveBeenCalledWith({"username": "", "password": "My new value"}); | ||
// }); | ||
// }); | ||
// | ||
// describe('Validacion: ', () => { | ||
// it('validate debe devolver un objeto con un error si el usarname no es un email valido:', () => { | ||
// expect(validate({ | ||
// username: 'dassadas', | ||
// password: 'hola1' | ||
// })).toEqual({username: 'Username is invalid'}); | ||
// }); | ||
// it('validate debe devolver un objeto con un error si el usarname esta vacio:', () => { | ||
// expect(validate({ | ||
// username: '', | ||
// password: 'hola1', | ||
// })).toEqual({username: 'Username is required'}); | ||
// }); | ||
// it('validate debe devolver un objeto con un error si el password no tiene un numero:', () => { | ||
// expect(validate({ | ||
// username: '[email protected]', | ||
// password: 'dassadas' | ||
// })).toEqual({password: 'Password is invalid'}); | ||
// }); | ||
// it('validate debe devolver un objeto con un error si el password esta vacio:', () => { | ||
// expect(validate({ | ||
// username: '[email protected]', | ||
// password: '' | ||
// })).toEqual({password: 'Password is required'}); | ||
// }); | ||
// }); | ||
// }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters