'pending' test 在 Mocha 中是什么意思,我怎样才能做到 pass/fail?
What does 'pending' test mean in Mocha, and how can I make it pass/fail?
我正在 运行 我的测试并注意到:
18 passing (150ms)
1 pending
我以前没见过这个。之前的测试要么通过,要么失败。超时导致失败。我可以看到哪个测试失败了,因为它也是蓝色的。但是它有超时时间。这是一个简化版本:
test(`Errors when bad thing happens`), function(){
try {
var actual = doThing(option)
} catch (err) {
assert(err.message.includes('invalid'))
}
throw new Error(`Expected an error and didn't get one!`)
}
- 'pending'是什么意思? 当 Mocha 退出且节点不再 运行 时,测试怎么会 'pending'?
- 为什么这个测试没有超时?
- 如何使测试通过或失败?
谢谢!
许多测试框架中的待定测试是 运行 人员决定不 运行 的测试。有时是因为测试被标记为要跳过。有时因为测试只是一个 TODO 的占位符。
对于 Mocha,documentation 表示挂起测试是没有任何回调的测试。
你确定你看的是好的测试吗?
测试had a callback(即实际功能,未完成)但重构代码解决了问题。问题是预期错误的代码应该如何 运行:
test('Errors when bad thing happens', function() {
var gotExpectedError = false;
try {
var actual = doThing(option)
} catch (err) {
if ( err.message.includes('Invalid') ) {
gotExpectedError = true
}
}
if ( ! gotExpectedError ) {
throw new Error(`Expected an error and didn't get one!`)
}
});
当您无意中提前关闭测试的 it
方法时,Mocha 可能最终将测试显示为 "pending",例如:
// Incorrect -- arguments of the it method are closed early
it('tests some functionality'), () => {
// Test code goes here...
};
it
方法的参数应包括测试函数定义,如:
// Correct
it('tests some functionality', () => {
// Test code goes here...
});
当我遇到这个问题时,挂起的错误是当我用 skip 定义一个 describe 测试时,忘记删除它,就像这样:
describe.skip('padding test', function () {
it('good test', function () {
expect(true).to.equal(true);
})
});
做了运行,我得到了输出
Pending test 'good test'
并且当我删除描述测试中的 skip 标志时,它再次起作用..
我正在 运行 我的测试并注意到:
18 passing (150ms)
1 pending
我以前没见过这个。之前的测试要么通过,要么失败。超时导致失败。我可以看到哪个测试失败了,因为它也是蓝色的。但是它有超时时间。这是一个简化版本:
test(`Errors when bad thing happens`), function(){
try {
var actual = doThing(option)
} catch (err) {
assert(err.message.includes('invalid'))
}
throw new Error(`Expected an error and didn't get one!`)
}
- 'pending'是什么意思? 当 Mocha 退出且节点不再 运行 时,测试怎么会 'pending'?
- 为什么这个测试没有超时?
- 如何使测试通过或失败?
谢谢!
许多测试框架中的待定测试是 运行 人员决定不 运行 的测试。有时是因为测试被标记为要跳过。有时因为测试只是一个 TODO 的占位符。
对于 Mocha,documentation 表示挂起测试是没有任何回调的测试。
你确定你看的是好的测试吗?
测试had a callback(即实际功能,未完成)但重构代码解决了问题。问题是预期错误的代码应该如何 运行:
test('Errors when bad thing happens', function() {
var gotExpectedError = false;
try {
var actual = doThing(option)
} catch (err) {
if ( err.message.includes('Invalid') ) {
gotExpectedError = true
}
}
if ( ! gotExpectedError ) {
throw new Error(`Expected an error and didn't get one!`)
}
});
当您无意中提前关闭测试的 it
方法时,Mocha 可能最终将测试显示为 "pending",例如:
// Incorrect -- arguments of the it method are closed early
it('tests some functionality'), () => {
// Test code goes here...
};
it
方法的参数应包括测试函数定义,如:
// Correct
it('tests some functionality', () => {
// Test code goes here...
});
当我遇到这个问题时,挂起的错误是当我用 skip 定义一个 describe 测试时,忘记删除它,就像这样:
describe.skip('padding test', function () {
it('good test', function () {
expect(true).to.equal(true);
})
});
做了运行,我得到了输出
Pending test 'good test'
并且当我删除描述测试中的 skip 标志时,它再次起作用..