From: Eduardo San Martin Morote Date: Wed, 12 May 2021 09:27:26 +0000 (+0200) Subject: test(actions): test rejects and throw X-Git-Tag: v0.5.0~20 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6d11fddb5b7344b7a4acb43058cc936e66eefd45;p=thirdparty%2Fvuejs%2Fpinia.git test(actions): test rejects and throw --- diff --git a/__tests__/actions.spec.ts b/__tests__/actions.spec.ts index 75abfa22..2b3ebb7f 100644 --- a/__tests__/actions.spec.ts +++ b/__tests__/actions.spec.ts @@ -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') + }) })