mercredi 30 décembre 2015

Ember - triggerEvent helper

I'm having trouble triggering a "change" event in an ember acceptance test.

I have a rangeslider with an observed 'value' property. On change, the slider sends an api request which updates the url with params based on the slider value.

I am able to change the value of the slider in my test using jQuery, which successfully updates the slider in the UI...

$("#slider").val(3.0).change();

...but the change event isn't fired, so no api call. This same setup is working fine for similar tests where I am able to use "click" or "fillIn" to trigger a request.

I've tried using both the run loop and the triggerEvent helper (see below) but am having no luck.

    // 1. using the run loop -- updates UI, but no change event fired

    Ember.run(function() {
      $("#gpa-slider").val(3.0).change();
    });
    andThen(() => {
      assert.equal(currentURL(), "/athletes?gpa=3.0")
    });


    //2. using triggerEvent helper -- 
    //   doesn't update UI, slider value, or trigger change event

    triggerEvent('#gpa-slider', 'change', {value: 3.8} )

    andThen(() => {
      assert.equal(currentURL(), "/athletes?gpa=3.0")
    });

Am I setting up triggerEvent() incorrectly? Is there a better way to handle this?




Aucun commentaire:

Enregistrer un commentaire