Al fin después de mucho trabajar ya hallamos la respuesta de este atolladero que algunos de nuestros usuarios de nuestro espacio han tenido. Si tienes algún detalle que aportar puedes dejar tu información.
Ejemplo: probar entradas con la biblioteca de pruebas de reacción
import React from'react'import render, fireEvent from'@testing-library/react'classCostInputextendsReact.Component
state =
value:'',removeDollarSign= value =>(value[0]==='$'? value.slice(1): value)getReturnValue= value =>(value ===''?'':`$$value`)handleChange= ev =>
ev.preventDefault()const inputtedValue = ev.currentTarget.value
const noDollarSign =this.removeDollarSign(inputtedValue)if(isNaN(noDollarSign))returnthis.setState( value:this.getReturnValue(noDollarSign))render()return(<input
value=this.state.value
aria-label="cost-input"
onChange=this.handleChange/>)constsetup=()=>const utils =render(<CostInput />)const input = utils.getByLabelText('cost-input')return
input,...utils,test('It should keep a $ in front of the input',()=>const input =setup()
fireEvent.change(input, target: value:'23')expect(input.value).toBe('$23'))test('It should allow a $ to be in the input when the value is changed',()=>const input =setup()
fireEvent.change(input, target: value:'$23.0')expect(input.value).toBe('$23.0'))test('It should not allow letters to be inputted',()=>const input =setup()expect(input.value).toBe('')// empty before
fireEvent.change(input, target: value:'Good Day')expect(input.value).toBe('')//empty after)test('It should allow the $ to be deleted',()=>const input =setup()
fireEvent.change(input, target: value:'23')expect(input.value).toBe('$23')// need to make a change so React registers "" as a change
fireEvent.change(input, target: value:'')expect(input.value).toBe(''))
Copy
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)