Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trigger 'input' for few input fields #121

Open
sheb-gregor opened this issue Aug 29, 2017 · 1 comment
Open

Trigger 'input' for few input fields #121

sheb-gregor opened this issue Aug 29, 2017 · 1 comment

Comments

@sheb-gregor
Copy link

sheb-gregor commented Aug 29, 2017

I tried to test the correct bindings of the v-model and encountered the following problem: changing the values of the 'input' elements and calling the .trigger('input') method always only triggers the first one.
So first assert pass, seconds fails.

 it('should render correct contents', () => {
    const wrapper = mount(Login, { store })
    expect(wrapper.find('h1')[0].text()).to.equal('Login')

    const username = wrapper.find('input')[0]
    const password = wrapper.find('input')[1]
    username.element.value = '[email protected]'
    password.element.value = 'test password'

    username.trigger('input')
    expect(wrapper.vm.credentials.username).to.equal('[email protected]')
    password.trigger('input')
    expect(wrapper.vm.credentials.password).to.equal('test password')
  })

Problem was solved by reorganizing of variables declarations.
In the code below all assertions pass.

  it('should render correct contents', () => {
    const wrapper = mount(Login, { store })
    expect(wrapper.find('h1')[0].text()).to.equal('Login')

    const username = wrapper.find('input')[0]
    username.element.value = '[email protected]'
    username.trigger('input')

    const password = wrapper.find('input')[1]
    password.element.value = 'test password'
    password.trigger('input')

    expect(wrapper.vm.credentials.username).to.equal('[email protected]')
    expect(wrapper.vm.credentials.password).to.equal('test password')
  })
@eddyerburgh
Copy link
Owner

I don't think there's an easy solution to this, apart from restructuring the test. Like you did. I'll leave this issue open and I can look into it in the future, but for the moment your rewrite is the best solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants