executeAsync不将返回值传递给回调

时间:2016-05-20 18:57:42

标签: javascript intern leadfoot

我使用实习JS / leadfood测试框架。我正在使用 executeAsync 。我希望executeAsync的返回值传递给executeAsync的回调,但这不会发生。应该做以下工作吗?

return  this.remote.get(require.toUrl(url));
    //do stuff
    .executeAsync(function (done) {

        require([<library>],
            function ([<function>]) {
                return <function which returns Promise>
                .then(function (value) {
                    return <function which returns Promise>
                ...
                }).then(function () {
                    done(window.location);

                })
            })

    })
    .then(function (loc) {
        console.log(loc);
    })

执行成功获取executeAsync中的最后一个回调。成功调用executeAsync的回调。但传递给executeAsync回调的值是undefined

修改 我发现即使你设置了一个非常大的ex​​ecuteAsync超时,如果你没有调用this.async(timeout)指定正确的超时(在写入时默认为30秒),这个超时将被忽略。所以问题是测试花费的时间超过30秒,传递给done的值没有进入executeAsync的回调。

2 个答案:

答案 0 :(得分:2)

executeAsync使用回调来确定其功能何时完成运行。此回调会自动作为最后一个参数传递(唯一的参数,如果您没有传递任何其他内容)到executeAsync函数:

define([
    'require',
    'intern!object'
], function (
    require,
    registerSuite
) {
    registerSuite({
        name: 'test',

        foo: function () {
            return this.remote.get(require.toUrl('./index.html'))
                .setExecuteAsyncTimeout(5000)
                .executeAsync(function (done) {
                    var promise = new Promise(function (resolve) {
                        setTimeout(function () {
                            resolve();
                        }, 1000);
                    });

                    promise.then(function () {
                        return new Promise(function (resolve) {
                            setTimeout(function () {
                                resolve();
                            }, 1000);
                        });
                    }).then(function () {
                        done(window.location);
                    });
                })
                .then(function (loc) {
                    // This prints out a full location object from the
                    // browser.
                    console.log(loc);
                }); 
        }
    });
});

答案 1 :(得分:0)

根据此处的Leadfoot文件

https://theintern.github.io/leadfoot/module-leadfoot_Command.html#executeAsync

  

返回

     

远程代码返回的值。只能返回可以序列化为JSON和DOM元素的值。

你从执行的函数返回什么?