diff --git a/docs/guide/browser/interactivity-api.md b/docs/guide/browser/interactivity-api.md index fe3a2db6c..c3778cf9b 100644 --- a/docs/guide/browser/interactivity-api.md +++ b/docs/guide/browser/interactivity-api.md @@ -469,8 +469,8 @@ test('can upload a file', async () => { // or you can access it directly on the locator await input.upload(file) - // you can also use file paths relative to the test file - await userEvent.upload(input, '../fixtures/file.png') + // you can also use file paths relative to the root of the project + await userEvent.upload(input, './fixtures/file.png') }) ``` diff --git a/packages/browser/src/node/commands/upload.ts b/packages/browser/src/node/commands/upload.ts index 0d9195e70..81b2580c5 100644 --- a/packages/browser/src/node/commands/upload.ts +++ b/packages/browser/src/node/commands/upload.ts @@ -1,6 +1,6 @@ import type { UserEventUploadOptions } from '@vitest/browser/context' import type { UserEventCommand } from './utils' -import { dirname, resolve } from 'pathe' +import { resolve } from 'pathe' import { PlaywrightBrowserProvider } from '../providers/playwright' import { WebdriverBrowserProvider } from '../providers/webdriver' @@ -18,13 +18,13 @@ export const upload: UserEventCommand<(element: string, files: Array { if (typeof file === 'string') { - return resolve(testDir, file) + return resolve(root, file) } return { name: file.name, @@ -44,7 +44,7 @@ export const upload: UserEventCommand<(element: string, files: Array { input.id = 'file' input.type = 'file' document.body.appendChild(input) - await userEvent.upload(input, '../src/button.css') + await userEvent.upload(input, './src/button.css') await expect.poll(() => input.files.length).toBe(1) const uploadedFile = input.files[0] @@ -929,7 +929,7 @@ describe('uploading files', async () => { input.type = 'file' input.multiple = true document.body.appendChild(input) - await userEvent.upload(input, ['../src/button.css', '../package.json']) + await userEvent.upload(input, ['./src/button.css', './package.json']) await expect.poll(() => input.files.length).toBe(2) const uploadedFile1 = input.files[0]