From: Eduardo San Martin Morote Date: Thu, 19 Aug 2021 17:04:52 +0000 (+0200) Subject: test: improve coverage X-Git-Tag: @pinia/testing@0.0.2~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5266bf5df6270e53d82c8391b244e6be1d3f4dbd;p=thirdparty%2Fvuejs%2Fpinia.git test: improve coverage --- diff --git a/packages/pinia/__tests__/state.spec.ts b/packages/pinia/__tests__/state.spec.ts index b39dd088..0a3c3fcd 100644 --- a/packages/pinia/__tests__/state.spec.ts +++ b/packages/pinia/__tests__/state.spec.ts @@ -193,4 +193,18 @@ describe('State', () => { 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, + }, + }) + }) }) diff --git a/packages/pinia/src/createPinia.ts b/packages/pinia/src/createPinia.ts index 15b8e731..00dd6282 100644 --- a/packages/pinia/src/createPinia.ts +++ b/packages/pinia/src/createPinia.ts @@ -32,6 +32,7 @@ export function createPinia(): Pinia { // this allows calling useStore() outside of a component setup after // installing pinia's plugin setActivePinia(pinia) + /* istanbul ignore else */ if (__DEV__) { registerPiniaDevtools(app, pinia) } diff --git a/packages/pinia/src/store.ts b/packages/pinia/src/store.ts index 02545365..ed3fbdcb 100644 --- a/packages/pinia/src/store.ts +++ b/packages/pinia/src/store.ts @@ -178,6 +178,7 @@ function createSetupStore< /* 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 diff --git a/packages/testing/src/testing.spec.ts b/packages/testing/src/testing.spec.ts index 04dd6f7f..ce48a8c2 100644 --- a/packages/testing/src/testing.spec.ts +++ b/packages/testing/src/testing.spec.ts @@ -25,7 +25,7 @@ describe('Testing', () => { `, }) - function factory(options: TestingOptions = {}) { + function factory(options?: TestingOptions) { const wrapper = mount(Counter, { global: { plugins: [createTestingPinia(options)], @@ -151,4 +151,24 @@ describe('Testing', () => { 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') + }) }) diff --git a/packages/testing/src/testing.ts b/packages/testing/src/testing.ts index e159a31a..044cbfaf 100644 --- a/packages/testing/src/testing.ts +++ b/packages/testing/src/testing.ts @@ -80,7 +80,7 @@ export function createTestingPinia({ } pinia.use(({ store, options }) => { - Object.keys(options.actions || {}).forEach((action) => { + Object.keys(options.actions).forEach((action) => { store[action] = stubActions ? createSpy() : createSpy(store[action]) })