Node.js 为什么摩卡说我的考试通过了,而它本不应该';T
目前,我不明白为什么终端说我的测试通过了。我的考试设置为不及格 这是终端信息:Node.js 为什么摩卡说我的考试通过了,而它本不应该';T,node.js,selenium,mocha.js,chai,Node.js,Selenium,Mocha.js,Chai,目前,我不明白为什么终端说我的测试通过了。我的考试设置为不及格 这是终端信息: Google ✓ Load google search page 1 passing (22ms) 这是我用NodeJS编写的测试 const assert = require('assert'); const {Builder, By, Key, until} = require('selenium-webdriver'); const suite = require('selenium-we
Google
✓ Load google search page
1 passing (22ms)
这是我用NodeJS编写的测试
const assert = require('assert');
const {Builder, By, Key, until} = require('selenium-webdriver');
const suite = require('selenium-webdriver/testing')
var driver = new Builder()
.forBrowser('chrome')
.build();
describe('Google', function() {
it('Load google search page', function() {
driver.get('https://www.foobar.com')
.then(_ => driver.wait(until.titleIs('Darkness!'), 10000))
.then(_ => driver.quit());
});
});
查看何时使用以下格式进行异步测试:
it('should be fulfilled', function (done) {
promise.should.be.fulfilled.and.notify(done);
});
it('should be rejected', function (done) {
otherPromise.should.be.rejected.and.notify(done);
});
适用于您的情况:
describe('Google', function() {
it('Load google search page', function(done) {
driver.get('https://www.foobar.com')
.then(() => driver.wait(until.titleIs('Darkness!'), 10000))
.then(() => driver.quit())
.then(() => done())
.catch(done);
});
});
不确定,但您正在等待10秒,然后干净地退出。没有任何错误,您没有任何期望,因此测试通过了。但我可能错了。测试可能在最后一个承诺(
driver.quit
)解决之前就存在了。根据设置的版本,您可能必须在异步
函数中使用wait
:换句话说,正如Florent所说。基本上,您不会等待异步操作完成并检查其结果。您只需立即从函数返回,而不会引发任何错误。错误不是自动处理的,您应该为它们断言(就像Gregory的回答)