chore: configurations and update deps
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
/*! fromentries. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
||||
export function fromEntries<T = any> (
|
||||
export function fromEntries<T = any>(
|
||||
iterable: Iterable<readonly [PropertyKey, T]>
|
||||
) {
|
||||
return [...iterable].reduce((object, [key, value]) => {
|
||||
|
40
src/index.test.tsx
Normal file
40
src/index.test.tsx
Normal file
@ -0,0 +1,40 @@
|
||||
import React from 'react'
|
||||
import Form, { HandleForm } from '.'
|
||||
import { render, cleanup, fireEvent } from '@testing-library/react'
|
||||
|
||||
afterEach(cleanup)
|
||||
|
||||
describe('Form component', () => {
|
||||
it('should get the formData and formElement onSubmit and onChange', () => {
|
||||
let formData: { [k: string]: any } = {}
|
||||
let formElement: any = null
|
||||
const handleSubmitChange: HandleForm = (data, element) => {
|
||||
formData = data
|
||||
formElement = element
|
||||
}
|
||||
const formComponent = render(
|
||||
<Form onSubmit={handleSubmitChange} onChange={handleSubmitChange}>
|
||||
<input data-testid='input-form' type='text' name='inputName' />
|
||||
<button data-testid='button-submit' type='submit'>
|
||||
Submit
|
||||
</button>
|
||||
</Form>
|
||||
)
|
||||
const inputForm = formComponent.getByTestId(
|
||||
'input-form'
|
||||
) as HTMLInputElement
|
||||
const buttonSubmit = formComponent.getByTestId('button-submit')
|
||||
const text = 'some random text'
|
||||
|
||||
fireEvent.change(inputForm, { target: { value: text } })
|
||||
expect(formData.inputName).toEqual(text)
|
||||
expect(formElement instanceof HTMLFormElement).toBeTruthy()
|
||||
formData = {}
|
||||
formElement = null
|
||||
|
||||
fireEvent.click(buttonSubmit)
|
||||
expect(Object.keys(formData).length).toEqual(1)
|
||||
expect(formData.inputName).toEqual(text)
|
||||
expect(formElement instanceof HTMLFormElement).toBeTruthy()
|
||||
})
|
||||
})
|
1
src/react-app-env.d.ts
vendored
Normal file
1
src/react-app-env.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
||||
/// <reference types="react-scripts" />
|
Reference in New Issue
Block a user