FAQ
Cette page a été traduite par PageTurner AI (bêta). Non approuvée officiellement par le projet. Vous avez trouvé une erreur ? Signaler un problème →
Comment tester l'upload de fichiers ?
Utilisez l'utilitaire upload de @testing-library/user-event. Il fonctionne parfaitement avec jsdom et 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)
})