【发布时间】:2017-09-17 16:01:33
【问题描述】:
我们使用 spectron 和 WebdriverIO 对电子应用程序进行了一些简单的“这是否真的有效”的 chai 测试。我们开始的示例代码来自
https://github.com/jwood803/ElectronSpectronDemo 正如https://github.com/jwood803/ElectronSpectronDemo/issues/2 中所报告的那样,chai-as-promised 测试没有发现不匹配,所以我想我会添加一些额外的测试来找出为什么 Chai 没有通过电子应用程序有文本的测试与预期的单元测试文本不匹配。
让我们从非常简单的开始,其余代码在https://github.com/drjasonharrison/ElectronSpectronDemo
describe('Test Example', function () {
beforeEach(function (done) {
app.start().then(function() { done(); } );
});
afterEach(function (done) {
app.stop().then(function() { done(); });
});
it('yes == no should fail', function () {
chai.expect("yes").to.equal("no");
});
it('yes == yes should succeed', function () {
chai.expect("yes").to.equal("yes");
});
第一个单元测试失败,第二个成功。
当我们将断言放入一个函数中时,它仍然会检测到失败:
it('should fail, but succeeds!?', function () {
function fn() {
var yes = 'yes';
yes.should.equal('no');
};
fn();
});
现在进入 electron、webdriverio 和 spectron 的世界,应用程序标题应该是“Hello World!”,所以这应该失败,但它通过了:
it('tests the page title', function () {
page.getApplicationTitle().should.eventually.equal("NO WAY");
});
嗯,让我们尝试一个更熟悉的测试:
it('should fail, waitUntilWindowLoaded, yes != no', function () {
app.client.waitUntilWindowLoaded().getTitle().then(
function (txt) {
console.log('txt = ' + txt);
var yes = 'yes';
yes.should.equal('no');
}
);
});
输出:
✓ should fail, waitUntilWindowLoaded, yes != no
txt = Hello World!
成功了吗?什么?为什么?怎么样?
【问题讨论】:
标签: node.js electron bdd chai spectron