用摩卡有条件地运行代码

时间:2017-08-31 11:17:18

标签: mocha

如何在运行mocha测试时运行一行代码,而在正常运行程序时运行另一行?

我想这样做是为了解决#34;陈旧参考错误" Selenium在删除之前无法访问和点击元素并替换为相同的元素(使用Angular)。

编辑 - 最小代码示例:

// File with tests
// todoElement is a section of the document element
var buttonPromise = todoElement.findElements(webdriver.By.tagName("button"));
buttonPromise.then(function(buttons) {
    buttons[1].click(); // Click the second button
    resolve();
});
//...

// Angular component file
//...
todos = [];
// Problem code that refreshes the page more quickly than Selenium can handle
setInterval(function() {
    refreshTodoList();
}, 1000);

this.refreshTodoList = function() {
    $http.get("/api/todo").then(function(response) {
        todos = response.data;
    }
    // Error handling
}

this.getTodos = function() {
    return todos;
}
//...

// HTML template File
//...
<li ng-repeat="listItem in $ctrl.getTodos()">
    <div>{{listItem.title}}</div>
    <button>Button 1</button>
    <button>Button 2</button>
</li>
//...

0 个答案:

没有答案