},
})
})
+
+ it('can reset the state of an empty store', () => {
+ const store = defineStore('a', {})(createPinia())
+ expect(store.$state).toEqual({})
+ store.$reset()
+ expect(store.$state).toEqual({})
+ })
})
import { createPinia, defineStore, MutationType, setActivePinia } from '../src'
import { mount } from '@vue/test-utils'
+import { nextTick } from 'vue'
describe('Subscriptions', () => {
const useStore = () => {
expect(spy2).toHaveBeenCalledTimes(3)
})
})
+
+ it('subscribe is post by default', async () => {
+ const spy = jest.fn()
+ store.$subscribe(spy)
+ store.$state.name = 'Cleiton'
+ expect(spy).toHaveBeenCalledTimes(0)
+ await nextTick()
+ expect(spy).toHaveBeenCalledTimes(1)
+ expect(spy).toHaveBeenCalledWith(
+ expect.objectContaining({
+ storeId: 'main',
+ type: MutationType.direct,
+ }),
+ store.$state
+ )
+ })
})
...options,
}
+ /* istanbul ignore if */
+ if (__DEV__ && !pinia._e.active) {
+ throw new Error('Pinia destroyed')
+ }
+
// watcher options for $subscribe
const $subscribeOptions: WatchOptions = {
deep: true,