Saltar al contenido principal

Preguntas frecuentes

[Traducción Beta No Oficial]

Esta página fue traducida por PageTurner AI (beta). No está respaldada oficialmente por el proyecto. ¿Encontraste un error? Reportar problema →


¿Cómo pruebo la subida de archivos?

Utiliza la utilidad upload de @testing-library/user-event. Funciona bien tanto en jsdom como en happy-dom.

test('upload file', async () => {
const user = userEvent.setup()

await render(<Uploader />)
const file = new File(['hello'], 'hello.png', {type: 'image/png'})
const input = screen.getByLabelText(/upload file/i)

await user.upload(input, file)

expect(input.files[0]).toBe(file)
expect(input.files.item(0)).toBe(file)
expect(input.files).toHaveLength(1)
})