简体   繁体   English

我怎样才能使这条线开玩笑? => jasmine.clock()。install();

[英]How can I make this line work in jest ? => jasmine.clock().install();

I have a unit test that use jasmin.clock.install 我有一个使用jasmin.clock.install的单元测试

I have the following error using jest-cli 20.0.4 我在使用jest-cli 20.0.4时遇到以下错误

TypeError: jasmine.clock is not a function

What package should I have in order to have this line work in my unit test : 为了使此行在我的单元测试中正常工作,我应该拥有什么软件包:

jasmine.clock().install();

I managed to make it work by downgrading to jest-cli 19.0.1. 我设法通过降级到jest-cli 19.0.1使其工作。 it would be nice to know the upgrade procedure. 很高兴知道升级过程。

From the docs jasmine.clock().install(); 从文档jasmine.clock().install(); is needed to mock out setTimeout calls. 需要模拟setTimeout调用。 So this can be done in Jest by using jest.useFakeTimers(); 因此,可以通过使用jest.useFakeTimers();在Jest中完成此操作jest.useFakeTimers(); . Have a look at the docs on how to mock timer in Jest. 看看有关如何在Jest中模拟计时器的文档 Also have a look at the announcement of v20 to see why the Jasmine stuff does not work anymore 也可以看看v20发布 ,看看为什么茉莉花的东西不再起作用了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM