3
我想用nightwatch.js和摩卡跑步者定义一些测试。我想测试我的JavaScript库如何在不同的浏览器中工作。异步测试与夜间和摩卡跑步者
我的代码是相当简单的,看起来像
const expect = require('chai').expect;
describe('InfinitiSpec', function() {
beforeEach((client, done) => {
client.url(`file://${__dirname}/../../dist/index.html`);
done();
});
after((client, done) => {
client.end(() => done());
});
it('should be five', (client) => {
client.execute(function() {
// test javascript here
}, [],() => {
expect(2 + 2).to.equal(5)
});
});
});
我的问题是,nightwatch没有通过done
回调测试,如果单个测试断言失败,测试本身仍然看起来因此,即使槽它是成功的。
vladmiller:infiniti-tracking-evolution vladmiller$ nightwatch
InfinitiSpec
✖ AssertionError: expected 4 to equal 5
at Object.<anonymous> (/Users/vladmiller/Projects/xxx/xxx/test/browser/infiniti.spec.js:18:24)
at HttpRequest.<anonymous> (/usr/local/lib/node_modules/nightwatch/lib/index.js:322:20)
at emitTwo (events.js:87:13)
at HttpRequest.emit (events.js:172:7)
at HttpRequest.<anonymous> (/usr/local/lib/node_modules/nightwatch/lib/index.js:351:15)
at emitThree (events.js:97:13)
at HttpRequest.emit (events.js:175:7)
at IncomingMessage.<anonymous> (/usr/local/lib/node_modules/nightwatch/lib/http/request.js:155:16)
at emitNone (events.js:72:20)
at IncomingMessage.emit (events.js:166:7)
✓ should be five (3322ms)
1 passing (3s)
如何使用nightwatch + mocha + chai测试异步javascript?也许可以推荐更好的堆栈在硒测试JS? 谢谢
我从来没有看到'client'参数之前。摩卡传递'done'作为'it/beforeEach/afterEach/before/after'中的第一个参数。你应该像导入'chai.expect'一样导入'client'。 – Louy
@Louy我认为你使用标准摩卡。请参阅文档参考http://nightwatchjs.org/guide#using-mocha Nightwatch可以在幕后集成摩卡(?) –
@Louy我之前从未使用硒,特别喜欢夜间表,因为它可以加载配置并给我很好的CLI工具。不过,我必须直接使用摩卡,我宁愿然后切换到webdriver –