8

DalekJS and Mithril: the tests are too fast

 2 years ago
source link: https://www.codesd.com/item/dalekjs-and-mithril-the-tests-are-too-fast.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

DalekJS and Mithril: the tests are too fast

advertisements

I use Dalek to test my sample to-do application written with help of Mithril framework.

Everything goes fine until .type() comes in.

If I .type() something in input that have bi-directional binding m.prop with m.withAttr and then assert values of that field i get strage behaviour. Instead "test title" I get "tsttle". It seems that test are running too quickly for Mithril to capture changes and render them back to DOM.

If assertions for input equality is removed — all works just fine.

Is there any workaround, can I slow down type process?

P.S. I use Chrome browser as test runner.


That definitely is an interesting issue, the problem is though, that Dalek can't control the speed of the letters typed. This is due to the fact that the JSON-Wire Protocol does not give us a way to handle that, see here

One thing you could do, even if it seems like overkill, is to add a long function chain with explicit waits, like this:

.type('#selector', 'H')
.wait(500)
.type('#selector', 'e')
.wait(500)
.type('#selector', 'l')
.wait(500)
.type('#selector', 'l')
.wait(500)
.type('#selector', 'o')

You also could go ahead & write a utility function that handles that for you

function myType (selector, keys, test, wait) {
  var keysArr = keys.split('');
  keysArr.forEach(function (key) {
    test.type(selector, key).wait(wait);
  });

  return test;
}

And then use it in your test like this:

module.exports = {
  'my test': function (test) {
    test.open('http://foobar.com');
    myType('#selector', 'Hello', test, 500);
    test.done();
  }
};


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK