Skip to content

Latest commit

 

History

History
34 lines (25 loc) · 784 Bytes

File metadata and controls

34 lines (25 loc) · 784 Bytes
id title sidebar_label
faq
FAQ
FAQ

How do I test file upload?

Use the upload utility from @testing-library/user-event. It works well in both jsdom and 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)
})