expect(store.counter).toBe(2)
expect(counter.value).toBe(2)
})
+
+ it('can reset the state', () => {
+ const store = useStore()
+ store.name = 'Ed'
+ store.nested.n++
+ store.$reset()
+ expect(store.$state).toEqual({
+ counter: 0,
+ name: 'Eduardo',
+ nested: {
+ n: 0,
+ },
+ })
+ })
})
// this allows calling useStore() outside of a component setup after
// installing pinia's plugin
setActivePinia(pinia)
+ /* istanbul ignore else */
if (__DEV__) {
registerPiniaDevtools(app, pinia)
}
/* istanbul ignore else */
if (__DEV__ && !isVue2) {
$subscribeOptions.onTrigger = (event) => {
+ /* istanbul ignore else */
if (isListening) {
debuggerEvents = event
// avoid triggering this while the store is being built and the state is being set in pinia
`,
})
- function factory(options: TestingOptions = {}) {
+ function factory(options?: TestingOptions) {
const wrapper = mount(Counter, {
global: {
plugins: [createTestingPinia(options)],
expect(counter.n).toBe(1)
expect(counterWithRealPinia.n).toBe(1)
})
+
+ it('works with no actions', () => {
+ const useEmpty = defineStore('empty', {})
+
+ const Empty = defineComponent({
+ setup() {
+ const empty = useEmpty()
+ return { empty }
+ },
+ template: `{{ empty.$id }}`,
+ })
+
+ const wrapper = mount(Empty, {
+ global: {
+ plugins: [createTestingPinia()],
+ },
+ })
+
+ expect(wrapper.text()).toBe('empty')
+ })
})
}
pinia.use(({ store, options }) => {
- Object.keys(options.actions || {}).forEach((action) => {
+ Object.keys(options.actions).forEach((action) => {
store[action] = stubActions ? createSpy() : createSpy(store[action])
})