我的测试组中有两个测试。其中一项测试使用 it
,另一项使用 test
。他们两个的工作方式似乎非常相似。它们之间有什么区别?
describe('updateAll', () => {
it('no force', () => {
return updateAll(TableName, ["fileName"], {compandId: "test"})
.then(updatedItems => {
let undefinedCount = 0;
for (let item of updatedItems) {
undefinedCount += item === undefined ? 1 : 0;
}
// console.log("result", result);
expect(undefinedCount).toBe(updatedItems.length);
})
});
test('force update', () => {
return updateAll(TableName, ["fileName"], {compandId: "test"}, true)
.then(updatedItems => {
let undefinedCount = 0;
for (let item of updatedItems) {
undefinedCount += item === undefined ? 1 : 0;
}
// console.log("result", result);
expect(undefinedCount).toBe(0);
})
});
});
更新 - 2022 年 11 月:
根据 Jest 的官方 API, 似乎 test
和 it
是可以互换的。正如 @gwildu 此处 所述,为了 可读性,您应该选择一个而不是另一个。
原文由 C.Lee 发布,翻译遵循 CC BY-SA 4.0 许可协议
Jest 文档 状态
it
是test
的别名。所以从功能的角度来看,它们是完全一样的。它们的存在都是为了让您的测试能够形成可读的英语句子。