我正在用 mocha 编写测试,检查从 rest api 轮询的变化状态是否正确呈现。是否可以在测试中间更改模拟端点返回的内容?我尝试过覆盖模拟端点并var
用作数据并更改它,但都不起作用。
使用覆盖:
it("should render correctly") {
loadPage(done, {init: function() {
testUtils.mockjax("/url", {"data": "data"})
}, onload: function() {
expect($$("#data")).to.be.visible()
testUtils.mockjax("/url", {"data": ""})
clock.tick(5000)
expect($$("#data")).not.to.be.visible() # does not work
...
done()
}
}
带变量:
it("should render correctly") {
var data = {"data": "data"}
loadPage(done, {init: function() {
testUtils.mockjax("/url", data)
}, onload: function() {
expect($$("#data")).to.be.visible()
data = {"data": ""}
clock.tick(5000)
expect($$("#data")).not.to.be.visible() # does not work
...
done()
}
}