Ember.JS集成测试问题与andThen并单击帮助程序

jak*_*ake 6 javascript integration-testing ember.js

我得到与Ember的测试助手奇怪的结果andThenclick.根据Ember的文件:

andThen助手将等待所有先前的异步助手之前进步向前来完成.

但是,我发现这似乎并非总是如此.在下面的示例中,有3个console.debug语句.我希望它们按照A - > B - > C的顺序记录.但是我一直得到这个顺序:A - > C - > B.当我只使用两次点击中的一次时,我只能获得预期的ABC顺序助手.没有与<div>单击助手中引用的元素关联的事件侦听器(操作).

谁能解释这种意想不到的行为?我使用助手时是否有错误?或者是Ember测试框架的错误?

andThen(function() {
    console.debug('mark A');

    click('div:first'); // with just 1 click helper, debug order is ABC
    click('div:first'); // with this second click helper, debug order is ACB

    andThen(function() {
        console.debug('mark B');
    });
});

andThen(function() {
    console.debug('mark C');
});
Run Code Online (Sandbox Code Playgroud)

编辑:

基于Kingpin2k给出的答案,我最终寻求以下解决方案来获得我正在寻求的测试风格.

首先,我创建了一个名为的异步测试助手next.其次,我用andThen自定义next助手替换了我的代码中的所有助手.这允许我的代码按照我期望的顺序运行.

// test-helper.js
Ember.Test.registerAsyncHelper('next', function(app, fn) {
    fn();
});

// my-integration-test.js
next(function() {
    console.debug('mark A');

    click('div:first');
    click('div:first');

    next(function() {
        console.debug('mark B');
    });
});

next(function() {
    console.debug('mark C');
});
Run Code Online (Sandbox Code Playgroud)

Kin*_*n2k 6

andThen它只是语法糖,lastPromiseEmberSawCreated.then 所以它看起来像这样:

lastPromiseEmberSawCreated.then(function(){
  console.debug('mark A');

    click('div:first'); // with just 1 click helper, debug order is ABC
    click('div:first'); // with this second click helper, debug order is ACB

  nextLastPromiseEmberSawCreated.then(function() {
        console.debug('mark B');
    });
});

// the promise won't have changed in between these two `andThen` calls 
// because Ember had no cpu time, and you didn't make any additional calls 

lastPromiseEmberSawCreated.then(function(){
    console.debug('mark C');
});
Run Code Online (Sandbox Code Playgroud)