【发布时间】:2017-12-19 21:20:44
【问题描述】:
我有一些使用 Intern (3) 运行的功能测试,测试的最后一步是进行一些清理,包括清除远程浏览器上的 localStorage,并通过立即存储窗口句柄切换回原始窗口并在测试结束之前切换回它(因此任何后续测试都不会失败,因为如果前一个测试在另一个测试结束时它们试图在关闭的窗口上运行)。但是,如果某些 chaijs 断言在 .then() 中失败,则最后的清理代码将被跳过。有没有更好的方法来清理即使在某些断言失败时仍会运行的功能测试?
this.leadfoot.remote
.get(require.toUrl(url))
.execute(function() { return document.querySelector('#welcome').textContent})
.then(welcome => {
assert.equal(welcome, 'hello world', 'properly greeted');
})
.execute(function() {
localStorage.clear();
});
如果断言失败,它永远不会在最后清除 localStorage,如果下一个运行的测试期望 localStorage 为空,它也会失败。功能测试后有没有更好的清理方法?
【问题讨论】:
标签: javascript functional-testing intern