-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Implement module mocking in browser mode #3046
Copy link
Copy link
Closed
Labels
enhancementNew feature or requestNew feature or requestfeat: browserIssues and PRs related to the browser runnerIssues and PRs related to the browser runner
Description
Describe the bug
The following test:
import { test, vi } from 'vitest'
import { v4 } from 'uuid'
vi.mock('uuid', () => ({
v4: 'I am mocked'
}))
test('I live in the browser', () => {
console.log('YES', window.navigator.userAgent, v4)
})throws an error:
FAIL tests/browser.test.js [ tests/browser.test.js ]
TypeError: this._mocker.queueMock is not a function
❯ VitestUtils.mock http:/localhost:63315/node_modules/.vite/deps/chunk-DGJ3HNQR.js?v=22cddd7a:10193:18
❯ http:/localhost:63315/private/tmp/vitestbrowser/tests/browser.test.js?v=1679345265563:4:4
Reproduction
see above
System Info
System:
OS: macOS 12.1
CPU: (10) arm64 Apple M1 Pro
Memory: 420.98 MB / 32.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 18.7.0 - ~/.nvm/versions/node/v18.7.0/bin/node
Yarn: 1.22.19 - ~/.nvm/versions/node/v18.7.0/bin/yarn
npm: 8.15.0 - ~/.nvm/versions/node/v18.7.0/bin/npm
Browsers:
Brave Browser: 111.1.49.120
Chrome: 111.0.5563.64
Firefox: 109.0
Firefox Nightly: 111.0a1
Safari: 15.2
npmPackages:
@vitest/browser: ^0.29.7 => 0.29.7
vitest: ^0.29.7 => 0.29.7Used Package Manager
npm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestfeat: browserIssues and PRs related to the browser runnerIssues and PRs related to the browser runner