为什么 mocha 说我的测试在不应该通过的时候通过了?
Why does mocha say my test is passing when it shouldn't?
目前,我不明白为什么终端说我的测试通过了。我的测试设置失败了。
这是终端消息:
Google
✓ Load google search page
1 passing (22ms)
这是我用 Node JS 编写的测试
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());
});
});
查看 documentation 当您想进行异步测试时使用以下格式:
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);
});
});
目前,我不明白为什么终端说我的测试通过了。我的测试设置失败了。
这是终端消息:
Google
✓ Load google search page
1 passing (22ms)
这是我用 Node JS 编写的测试
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());
});
});
查看 documentation 当您想进行异步测试时使用以下格式:
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);
});
});