1

私はインターンでいくつかの機能テストを書いていて、次のテキストセクションに出くわしました...

「テストのタイムアウト内に promise が満たされない場合も、テストは失敗します (デフォルトは 30 秒です。値を変更するには、this.timeout を設定します)。」

で...

https://github.com/theintern/intern/wiki/Writing-Tests-with-Intern#asynchronous-testing

機能テストの promise タイムアウトを設定するにはどうすればよいですか? promise で timeout() を直接呼び出してみましたが、有効な方法ではありません。

すでにさまざまな WD タイムアウト (ページ読み込みタイムアウト、暗黙の待機など) を設定していますが、promise のタイムアウトに問題があります。

4

5 に答える 5

1

提案された API を使用してテストでタイムアウトを設定しても、うまくいきませんでした。理想とはかけ離れていますが、最終的に Test.js を直接変更し、タイムアウトでハードコーディングしました。ソースを調べたときに、タイムアウト コードに次のようなコメントがあることに気付きました // TODO タイムアウトはまだ正しく機能していません

于 2014-09-29T10:50:08.153 に答える
1

defaultTimeout: 90000構成ファイル (tests/intern.jsデフォルトのチュートリアル コードベース内) に追加して、タイムアウトをグローバルに設定することもできます。これは私にとってはうまくいきます。

于 2016-05-17T12:20:42.350 に答える
1

最新バージョンでは問題なく動作しているようです:

define([
    'intern!object',
    'intern/chai!assert',
    'require',
    'intern/dojo/node!leadfoot/helpers/pollUntil'
], function (registerSuite, assert, require, pollUntil) {
    registerSuite(function(){
        return {
            name: 'index',

            setup: function() {         
            },

            'Test timeout': function () {           
                this.timeout = 90000;
                return this.remote.sleep(45000);
            }
        }
    });
});
于 2015-04-10T18:55:11.180 に答える
0

InternJS 4 を使用し、機能テストにasync/を使用しているときにここにたどり着いた人にとっては、私にはうまくいかないでしょうが、以下のパターンはうまくいきました。基本的に、私はいくつかのロジックを実行し、メソッドよりも長い間隔でメソッドを使用しました。内のrunはブロック スコープであるため、オブジェクトで後で参照したいものはすべてキャッシュする必要があることに注意してください。うまくいけば、これが他の誰かの時間と欲求不満を救うでしょう...awaittimeoutexecuteAsyncsleepsetTimeoutjavascriptexecutewindow

test(`timer test`, async ({remote}) => {
    await remote.execute(`
        // run setup logic, keep in mind this is scoped and if you want to reference anything it should be window scoped
        window.val = "foo";
        window.setTimeout(function(){
            window.val = "bar";
        }, 50);
        return true;
    `);
    await remote.sleep(51); // remote will chill for 51 ms
    let data = await remote.execute(`
        // now you can call the reference and the timeout has run
        return window.val;
    `);
    assert.strictEqual(
      data,
      'bar',
      `remote.sleep(51) should wait until the setTimeout has run, converting window.val from "foo" to "bar"`
    );
});
于 2019-04-30T21:09:34.147 に答える