]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
test(actions): test rejects and throw
authorEduardo San Martin Morote <posva13@gmail.com>
Wed, 12 May 2021 09:27:26 +0000 (11:27 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Wed, 12 May 2021 09:27:26 +0000 (11:27 +0200)
__tests__/actions.spec.ts

index 991629bce16e71a7766b105ef5637eff46b9e3f6..746dc0116446ef5f935104dfd4b232d597ac68a9 100644 (file)
@@ -37,6 +37,14 @@ describe('Actions', () => {
           this.toggle()
           this.setFoo('bar')
         },
+
+        throws() {
+          throw new Error('fail')
+        },
+
+        async rejects() {
+          throw 'fail'
+        },
       },
     })()
   }
@@ -114,4 +122,15 @@ describe('Actions', () => {
     bStore = useB(pinia1)
     expect(bStore.$state.b).toBe('a')
   })
+
+  it('throws errors', () => {
+    const store = useStore()
+    expect(() => store.throws()).toThrowError('fail')
+  })
+
+  it('throws async errors', async () => {
+    const store = useStore()
+    expect.assertions(1)
+    await expect(store.rejects()).rejects.toBe('fail')
+  })
 })