Search code examples
google-chromedalekjsmithril.js

DalekJS and Mithril: Test are too fast


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.


Solution

  • 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();
      }
    };