diff --git a/tests/utility/upload.ts b/tests/utility/upload.ts index ad887347..f63093d1 100644 --- a/tests/utility/upload.ts +++ b/tests/utility/upload.ts @@ -1,4 +1,5 @@ -import {setup} from '#testHelpers' +import {render, setup} from '#testHelpers' +import userEvent from '#src' test('change file input', async () => { const file = new File(['hello'], 'hello.png', {type: 'image/png'}) @@ -225,3 +226,25 @@ test('throw error if trying to use upload on an invalid element', async () => { `The associated INPUT element does not accept file uploads`, ) }) + +test('uploaded file can be read with FormData', async () => { + const file = new File(['hello'], 'hello.png', {type: 'image/png'}) + const {element: form} = render( + '
', + ) + + const input = form.querySelector('input') as HTMLInputElement + + await userEvent.upload(input, file) + + const data = new FormData(form) + + const formFile = data.get('file') + if (!(formFile instanceof File)) { + throw new Error('formFile is not a File') + } + + expect(formFile).toBeInstanceOf(File) + expect(formFile.name).toBe('hello.png') + expect(formFile).toBe(input.files?.[0]) +})