-
-
Notifications
You must be signed in to change notification settings - Fork 973
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #255 BREAKING CHANGE: `setActiveReq()` has been renamed to `setActivePinia()`. And now receives the application's pinia as the first parameter instead of an arbitrary object (like a Node http request). **This affects particularily users doing SSR** but also enables them to write universal code.
- Loading branch information
Showing
16 changed files
with
405 additions
and
216 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
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
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
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,105 @@ | ||
import { createPinia, defineStore, setActivePinia } from '../src' | ||
import { mount } from '@vue/test-utils' | ||
import { watch, nextTick, ref } from 'vue' | ||
|
||
describe('Store Lifespan', () => { | ||
function defineMyStore() { | ||
return defineStore({ | ||
id: 'main', | ||
state: () => ({ | ||
a: true, | ||
n: 0, | ||
nested: { | ||
foo: 'foo', | ||
a: { b: 'string' }, | ||
}, | ||
}), | ||
getters: { | ||
double() { | ||
return this.n * 2 | ||
}, | ||
notA() { | ||
return !this.a | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
const pinia = createPinia() | ||
// let pinia: object | ||
|
||
// const useStore = () => { | ||
// // create a new store | ||
// pinia = {} | ||
// setActivePinia(pinia) | ||
// return defineMyStore()() | ||
// } | ||
|
||
it('bug report', async () => { | ||
const inComponentWatch = jest.fn() | ||
|
||
const n = ref(0) | ||
|
||
const wrapper = mount( | ||
{ | ||
render: () => null, | ||
setup() { | ||
watch(() => n.value, inComponentWatch) | ||
n.value++ | ||
}, | ||
}, | ||
{ | ||
global: { | ||
plugins: [pinia], | ||
}, | ||
} | ||
) | ||
|
||
await wrapper.unmount() | ||
|
||
expect(inComponentWatch).toHaveBeenCalledTimes(1) | ||
|
||
// store!.n++ | ||
n.value++ | ||
await nextTick() | ||
expect(inComponentWatch).toHaveBeenCalledTimes(1) | ||
}) | ||
|
||
it('state reactivity outlives component life', async () => { | ||
const useStore = defineMyStore() | ||
setActivePinia(createPinia()) | ||
|
||
const inComponentWatch = jest.fn() | ||
|
||
let store: ReturnType<typeof useStore> | ||
|
||
const n = ref(0) | ||
|
||
const wrapper = mount( | ||
{ | ||
render: () => null, | ||
setup() { | ||
store = useStore() | ||
// watch(() => store.n, inComponentWatch) | ||
watch(() => n.value, inComponentWatch) | ||
store.n++ | ||
n.value++ | ||
}, | ||
}, | ||
{ | ||
global: { | ||
plugins: [pinia], | ||
}, | ||
} | ||
) | ||
|
||
await wrapper.unmount() | ||
|
||
expect(inComponentWatch).toHaveBeenCalledTimes(1) | ||
|
||
// store!.n++ | ||
n.value++ | ||
await nextTick() | ||
expect(inComponentWatch).toHaveBeenCalledTimes(1) | ||
}) | ||
}) |
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
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
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
Oops, something went wrong.