]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
test: improve coverage
authorEduardo San Martin Morote <posva13@gmail.com>
Thu, 19 Aug 2021 17:04:52 +0000 (19:04 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Thu, 19 Aug 2021 17:04:52 +0000 (19:04 +0200)
packages/pinia/__tests__/state.spec.ts
packages/pinia/src/createPinia.ts
packages/pinia/src/store.ts
packages/testing/src/testing.spec.ts
packages/testing/src/testing.ts

index b39dd088c7378cb44bb4fb2f0260601e6946fe6d..0a3c3fcd91fd8ee720f5b6b2a6dc194e34557133 100644 (file)
@@ -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,
+      },
+    })
+  })
 })
index 15b8e7315ede5d0ada07ab94c892fb11437acde1..00dd62820b7da4f2657c281578a17bb47c04ae82 100644 (file)
@@ -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)
           }
index 02545365ab003303de451f251d15b88aedb20b6b..ed3fbdcbbc2fbd32de5c5ccb9f7865aa9c82dd4a 100644 (file)
@@ -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
index 04dd6f7f483233f7e8ea490ff3ccf58b629f2a33..ce48a8c2cbe4753c643fd7ccae1922e641e5b5ac 100644 (file)
@@ -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')
+  })
 })
index e159a31ac240c2ece007ef3a82a2eb5e886077f7..044cbfaf27500e947764b13fbeffc653033aa58a 100644 (file)
@@ -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])
     })