formhero/test/shared.tsx

24 lines
663 B
TypeScript
Raw Normal View History

2023-03-03 22:08:54 +00:00
import { fireEvent, screen } from '@testing-library/react'
import React from 'react'
import { expect } from 'vitest'
export const Insight = {
Portal({ data }: { data: any }) {
return <div data-testid="result">{JSON.stringify(data)}</div>
},
async verify(obj: any) {
const result = await screen.findByTestId('result')
const data = JSON.parse(result.innerText)
expect(data).toMatchObject(obj)
},
}
export const Util = {
find<E extends HTMLElement = HTMLInputElement>(id: string) {
return screen.findByTestId<E>(id)
},
writeToField(node: HTMLInputElement, value: string) {
fireEvent.change(node, { target: { value } })
},
}