]> 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>
Thu, 13 May 2021 11:07:17 +0000 (13:07 +0200)
__tests__/actions.spec.ts

index 75abfa221a9dfb563b06c27c71f5566e32c5805b..2b3ebb7f8dfab486667d85f10b3092ebd9254377 100644 (file)
@@ -41,6 +41,14 @@ describe('Actions', () => {
           this.toggle()
           this.setFoo('bar')
         },
+
+        throws() {
+          throw new Error('fail')
+        },
+
+        async rejects() {
+          throw 'fail'
+        },
       },
     })()
   }
@@ -122,4 +130,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')
+  })
 })