让Mocha等待UI更新

时间:2015-07-21 10:36:27

标签: testing mocha chai

我使用Mocha和Chai作为编写测试的web-component-tester工具的一部分。作为这些测试的一部分,我需要等待UI的一部分在进行断言之前进行更新。

我能够弄清楚如何成功完成此操作的唯一方法是使用超时:

test("should update image", function(done) {
  setTimeout(function() {
      assert.equal(document.querySelector(".tp-revslider-mainul .tp-revslider-slidesli:nth-child(1) .tp-bgimg").getAttribute("src"), "https://someurl/image.jpg");
      done();
  }, 5000);
});

有更好的方法吗? CasperJS有一个waitFor函数,在这种情况下表现很好,但我不确定如何在Mocha中做同样的事情。

THX。

0 个答案:

没有答案
相关问题