-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(devtools): Do not patch mocked actions (#2300)
- Loading branch information
1 parent
938d389
commit 069ffd1
Showing
2 changed files
with
51 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { describe, it, expect } from 'vitest' | ||
import { mount } from '@vue/test-utils' | ||
import { createPinia, defineStore } from '../src' | ||
import { devtoolsPlugin } from '../src/devtools' | ||
|
||
describe('devtoolsPlugin', () => { | ||
const useStore = defineStore('test', { | ||
actions: { | ||
myAction() { | ||
return 42 | ||
}, | ||
}, | ||
}) | ||
|
||
it('preserves mocked actions during testing', () => { | ||
const pinia = createPinia() | ||
// Simulate using createTestingPinia | ||
pinia._testing = true | ||
|
||
mount({ template: 'none' }, { global: { plugins: [pinia] } }) | ||
|
||
// Simulate mocking with @pinia/testing createSpy | ||
pinia.use(({ store, options }) => { | ||
Object.keys(options.actions).forEach((action) => { | ||
store[action]._mockImplementation = () => {} | ||
}) | ||
}) | ||
// Previously the mocked actions would be wrapped again | ||
pinia.use(devtoolsPlugin) | ||
|
||
const store = useStore(pinia) | ||
|
||
// @ts-expect-error we have not actually loaded @pinia/testing and mocked actions | ||
expect(store.myAction._mockImplementation).toBeDefined() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters