From 6d11fddb5b7344b7a4acb43058cc936e66eefd45 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Wed, 12 May 2021 11:27:26 +0200 Subject: [PATCH] test(actions): test rejects and throw --- __tests__/actions.spec.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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') + }) }) -- 2.47.3