-1

我正在使用实习生 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.

编辑: 我发现即使您设置了一个非常大的 executeAsync 超时,如果您不调用this.async(timeout)指定正确的超时(在撰写本文时默认为 30 秒),则此超时将被忽略。所以问题是测试花费的时间超过 30 秒,并且传递给 done 的值没有进入到 executeAsync 的回调。

4

2 回答 2

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);
                }); 
        }
    });
});
于 2016-05-21T13:45:55.107 回答
0

根据此处的 Leadfoot 文件

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

退货

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

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

于 2016-05-21T12:45:14.310 回答