vendredi 1 mai 2015

Ember acceptance test - timeouts

I have a reasonably special use-case: I have an input field which issues a search when the user has stopped typing for 500ms. This is developed as a reusable add-on.

I would like to write an acceptance test for this but I cannot make the tests pass properly. The first passes, the second doesn't.

Now, the Ember runloop has a nice description but it's behaviour is really "something else".

This is my helper to timeout the runloop:

import Ember from 'ember';

export default Ember.Test.registerAsyncHelper('pauseFor', function (time) {
  return Ember.Test.promise(function (resolve) {
    Ember.run.later(resolve, time);
  });
});

And this is how I use it

it('should do something after 500ms', function () {
  visit('/');

  fillIn('.search-input', 'a');
  pauseFor(500);

  andThen(function () {
    // do my assertions/expectations here...
  });
});

This is the error I get: enter image description here

The weird thing is that I have 2 test cases and the first passes happily.

I guess my question is: How to do this properly? What am I missing here or what am I doing wrong? How can I just simply timeout the test case?

Thanks for the halp!

Aucun commentaire:

Enregistrer un commentaire