From 96dde1d8322cae351bff4468ff27490ff42112be 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 991629bc..746dc011 100644 --- a/__tests__/actions.spec.ts +++ b/__tests__/actions.spec.ts @@ -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') + }) }) -- 2.47.3