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.
This commit is contained in:
Robert Schäfer 2019-07-08 17:42:53 +02:00
parent d76923c471
commit 29bbeaa0fa
4 changed files with 18 additions and 9 deletions

View File

@ -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')
})
})

View File

@ -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) {

View File

@ -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',

View File

@ -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!')