question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Changing values and triggering inputs

See original GitHub issue

I am currently on avoriaz 1.13.1 and use simulate() pretty regularly in my Vue Component tests as so:

const component = mount(SearchForm)
const searchInput = component.find("input#search")[0]
searchInput.element.value = 'Jane Doe'
searchInput.simulate('input')

These specs work correctly and pass.

As I upgraded to avoriaz 2.4.3, and I change the deprecated simulate() to trigger(), the specs fail. I also noticed that if I console log searchInput.element, it will log HTMLInputElement { _prevClass: '', _value: '' }, and if I console log searchInput.element.value, it console logs nothing. Previously, console logging searchInput.element.value would return a value and would be set correctly. I have looked around and am wondering why when I upgrade, searchInput.element.value doesn’t seem to be returning anything like it use to.

I am still learning a lot about Vue and avoriaz, so it is quite possible I just missed something. But was wondering if you had any ideas @eddyerburgh. Thanks for any help 😄

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
justincscott16commented, Jul 31, 2017

@eddyerburgh works great, all my specs passed with simply replacing simulate with trigger. Also, switching to Vue.use(Vuex) was a simple find and replace from what I had which was avoriaz.use(Vuex).

Thanks for the help and the quick response and fix, you are the man, love your software!

1reaction
justincscott16commented, Jul 28, 2017

@eddyerburgh finally got to getting back to this! Here we go, a super basic component with an input, and then the two tests, one with trigger() and one with simulate()! Also I am running this on avoriaz 2.4.3.

// SearchForm.vue

<template>
  <div>
    <form method='get' action='some.api.endpoint' accept-charset="utf-8">
      <input id='query' v-model="searchQuery" name='query' type='search'>
      <input type='submit' value='Search'>
    </form>
  </div>
</template>

<script>
export default {
  name: 'search-form',
  data: function () {
    return {
      searchQuery: ''
    }
  }
}
</script>

// SearchForm.test.js

import Vue from 'vue'
import { expect } from 'chai'
import avoriaz, { mount } from 'avoriaz'
import SearchForm from '../path/to/SearchForm.vue'

Vue.config.productionTip = false

describe('SearchForm.vue', () => {

  // This passes
  it('changes input with simulate()', () => {
    let component = mount(SearchForm)
    const searchInput = component.find('input#query')[0]
    searchInput.element.value = 'hello'
    searchInput.simulate('input')
    expect(searchInput.element.value).to.eq('hello')
  })

  // This does not
  it('changes input with trigger()', () => {
    let component = mount(SearchForm)
    const searchInput = component.find('input#query')[0]
    searchInput.element.value = 'hello'
    searchInput.trigger('input')
    expect(searchInput.element.value).to.eq('hello')
  })
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

val() doesn't trigger change() in jQuery - Stack Overflow
Title itself answered my question. Confirmed at .change() yellow "Note: Changing the value of an input element using JavaScript, using .val() for example,...
Read more >
Events: change, input, cut, copy, paste
The input event triggers every time after a value is modified by the user. Unlike keyboard events, it triggers on any value change,...
Read more >
Trigger .change after setting the new value for more flexibility
Hello,. When you dynamically set a value in a textfield using jQuery .val(), you have to manually trigger the .change event if you...
Read more >
Issue with "An input value has changed" trigger - Bubble Forum
I have several workflows that are triggered by an input value changing. However, the results are inconsistent and values don't update ...
Read more >
Primitive input onChange event does not trigger on value ...
Primitive input onChange event does not trigger on value change iOS. complete ... The on change seems to trigger only once, once the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found