From f85081c3087635db434fe8c0a3ac64f65574a75e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=A4fer?= Date: Wed, 19 Dec 2018 17:58:03 +0100 Subject: [PATCH] Properly test the reject branch of `login` --- store/auth.test.js | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/store/auth.test.js b/store/auth.test.js index 9160d0cc5..e05becb57 100644 --- a/store/auth.test.js +++ b/store/auth.test.js @@ -114,10 +114,12 @@ describe('actions', () => { }) describe('given invalid credentials and incorrect password response', () => { + let onLogin + let mutate + beforeEach(() => { - const response = Object.assign({}, incorrectPasswordResponse) - const mutate = jest.fn(() => Promise.resolve(response)) - const onLogin = jest.fn(() => Promise.resolve()) + mutate = jest.fn(() => Promise.reject('This error is expected.')) + onLogin = jest.fn(() => Promise.resolve()) const module = { app: { apolloProvider: { defaultClient: { mutate } }, @@ -131,22 +133,18 @@ describe('actions', () => { action = null }) - xit('shows a user friendly error message', async () => { - await action( - { commit }, - { email: 'user@example.org', password: 'wrong' } - ) + it('populates error messages', async () => { + expect(action({ commit }, { email: 'user@example.org', password: 'wrong' })) + .rejects + .toThrowError('This error is expected.') + expect(mutate).toHaveBeenCalled() + expect(onLogin).not.toHaveBeenCalled() }) it('saves pending flags in order', async () => { try { - await action( - { commit }, - { email: 'user@example.org', password: 'wrong' } - ) - } catch (err) { - console.log(err) - } + await action({ commit }, { email: 'user@example.org', password: 'wrong' }) + } catch(err) {} // ignore expect(commit.mock.calls).toEqual( expect.arrayContaining([ ['SET_PENDING', true],