使用带有角度测试的角度测试fakeAsync it.each [英] using angular testing fakeAsync with jest it.each
本文介绍了使用带有角度测试的角度测试fakeAsync it.each的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用Angular 8,@ angular-builders/jest 8.0.2,jest 24.8,并通过以下测试通过
Using Angular 8, @angular-builders/jest 8.0.2, jest 24.8, and given the following test passes
import { tick, fakeAsync } from '@angular/core/testing';
it('test 1000 milliseconds', fakeAsync(() => {
const fn = jest.fn();
setTimeout(() => {
fn();
}, 1000);
tick(999);
expect(fn).not.toHaveBeenCalled();
tick(1);
expect(fn).toHaveBeenCalled();
}));
我想使用 it.each
it.each([[1000], [2000], [3000]])(
'test %d milliseconds',
fakeAsync(milliseconds => {
const fn = jest.fn();
setTimeout(() => {
fn();
}, milliseconds);
tick(milliseconds - 1);
expect(fn).not.toHaveBeenCalled();
tick(1);
expect(fn).toHaveBeenCalled();
}),
);
但是我在每次测试中都遇到了这个错误:
but I got this error on each test:
Expected to be running in 'ProxyZone', but it was not found.
at Function.Object.<anonymous>.ProxyZoneSpec.assertPresent (node_modules/zone.js/dist/proxy.js:42:19)
at node_modules/zone.js/dist/fake-async-test.js:588:47
我想念什么?
推荐答案
到目前为止,我想到的最好的解决方法是将 each
部分移动到 describe
包装器中以便将 fakeAsync
用于经典"广告系列中. it
.
So far, the best workaround I thought of was to move the each
part to a describe
wrapper so that fakeAsync
is used in a "classic" it
.
describe.each([[1000], [2000], [3000]])(
'test %d milliseconds',
milliseconds => {
it('', fakeAsync(() => {
const fn = jest.fn();
setTimeout(() => {
fn();
}, milliseconds);
tick(milliseconds - 1);
expect(fn).not.toHaveBeenCalled();
tick(1);
expect(fn).toHaveBeenCalled();
}));
},
);
它给测试代码和控制台输出增加了一些干扰,但至少现在测试通过了.
It adds some noise to the test code and to the console output, but at least, the tests now pass.
这篇关于使用带有角度测试的角度测试fakeAsync it.each的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文