From 29bbeaa0fae4cd4d85dc0c64cdc8b847c6a192eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=A4fer?= Date: Mon, 8 Jul 2019 17:42:53 +0200 Subject: [PATCH] Fix tests by calling `wrapper.html()` once more I really don't understand why, but apparently `wrapper.html()` does some re-rendering which in our cases fixes the tests, because we reach the new sub component in the DOM tree. --- .../Registration/CreateUserAccount.spec.js | 15 +++++++++++---- .../components/Registration/CreateUserAccount.vue | 5 +++-- webapp/components/Registration/Signup.spec.js | 5 +++-- webapp/pages/registration/create-user-account.vue | 2 +- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/webapp/components/Registration/CreateUserAccount.spec.js b/webapp/components/Registration/CreateUserAccount.spec.js index f8364ca0d..05a11bc33 100644 --- a/webapp/components/Registration/CreateUserAccount.spec.js +++ b/webapp/components/Registration/CreateUserAccount.spec.js @@ -56,6 +56,7 @@ describe('CreateUserAccount', () => { wrapper.find('input#password').setValue('hellopassword') wrapper.find('input#confirmPassword').setValue('hellopassword') await wrapper.find('form').trigger('submit') + await wrapper.html() } }) @@ -100,22 +101,28 @@ describe('CreateUserAccount', () => { describe('after timeout', () => { beforeEach(jest.useFakeTimers) - it('emits `userCreated` with user', async () => { + it('emits `userCreated` with { password, email }', async () => { await action() jest.runAllTimers() - expect(wrapper.emitted('userCreated')).toBeTruthy() + expect(wrapper.emitted('userCreated')).toEqual([ + [ + { + email: 'sixseven@example.org', + password: 'hellopassword', + }, + ], + ]) }) }) }) describe('in case mutation rejects', () => { beforeEach(() => { - mocks.$apollo.mutate.mockRejectedValue(new Error('Invalid nonce')) + mocks.$apollo.mutate = jest.fn().mockRejectedValue(new Error('Invalid nonce')) }) it('displays form errors', async () => { await action() - jest.runAllTimers() expect(wrapper.find('.errors').text()).toContain('Invalid nonce') }) }) diff --git a/webapp/components/Registration/CreateUserAccount.vue b/webapp/components/Registration/CreateUserAccount.vue index f38ebe509..4b91ab216 100644 --- a/webapp/components/Registration/CreateUserAccount.vue +++ b/webapp/components/Registration/CreateUserAccount.vue @@ -143,12 +143,13 @@ export default { try { await this.$apollo.mutate({ mutation: SignupVerificationMutation, - variables: { name, password, about, email, nonce } + variables: { name, password, about, email, nonce }, }) this.success = true setTimeout(() => { this.$emit('userCreated', { - email, password + email, + password, }) }, 3000) } catch (err) { diff --git a/webapp/components/Registration/Signup.spec.js b/webapp/components/Registration/Signup.spec.js index eb0d65d42..e66b39bb7 100644 --- a/webapp/components/Registration/Signup.spec.js +++ b/webapp/components/Registration/Signup.spec.js @@ -90,6 +90,7 @@ describe('Signup', () => { wrapper = Wrapper() wrapper.find('input#email').setValue('mail@example.org') await wrapper.find('form').trigger('submit') + await wrapper.html() } }) @@ -117,7 +118,7 @@ describe('Signup', () => { ) }) - it.skip('explains the error', async () => { + it('explains the error', async () => { await action() expect(mocks.$t).toHaveBeenCalledWith('registration.signup.form.errors.email-exists') }) @@ -132,7 +133,7 @@ describe('Signup', () => { ) }) - it.skip('explains the error', async () => { + it('explains the error', async () => { await action() expect(mocks.$t).toHaveBeenCalledWith( 'registration.signup.form.errors.invalid-invitation-token', diff --git a/webapp/pages/registration/create-user-account.vue b/webapp/pages/registration/create-user-account.vue index 812e4ec60..677aea5eb 100644 --- a/webapp/pages/registration/create-user-account.vue +++ b/webapp/pages/registration/create-user-account.vue @@ -13,7 +13,7 @@ export default { CreateUserAccount, }, methods: { - async handleUserCreated({email, password}) { + async handleUserCreated({ email, password }) { try { await this.$store.dispatch('auth/login', { email, password }) this.$toast.success('You are logged in!')