【发布时间】:2020-08-19 06:35:31
【问题描述】:
我正在开发和测试 Array.isArray 模块。
isArray 模块
export isArray function (arg) {
if (Array.isArray) {
return Array.isArray(arg);
}
return Object.prototype.toString.call(arg) === '[object Array]';
}
isArray TC
describe('isArray test', () => {
describe('[native] test', () => {
test('[] => true', () => {expect(isArray([])).toBe(true); });
});
describe('[native not exist] test', () => {
delete Array.isArray;
test('[] => true', () => {expect(isArray([])).toBe(true); });
});
});
delete Array.isArray 阶段似乎正在提升。 因此,所有 TC 都不是 isArray 模块的原生代码。 描述阶段在 TC 中提升? 请告诉 mw 如何使其不受影响的删除阶段。
【问题讨论】:
-
提升只与声明有关,其他任何事情都没有这种机制。不过,我不清楚这里的问题是什么 - 你如何确定
delete总是先运行? -
另请注意,与 test/it/afterX/beforeX 回调相反,describe 回调的内容在测试定义时间而不是在测试执行时间运行。
-
测试定义在执行时执行。并且 delete Array.isArray 阶段在定义时执行。我认为这个问题是定义和执行时间。
标签: javascript jestjs testcase