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