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: v2.0.0-alpha.17~31 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=96dde1d8322cae351bff4468ff27490ff42112be;p=thirdparty%2Fvuejs%2Fpinia.git test(actions): test rejects and throw --- 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') + }) })