我正在编写一个单元测试,测试一个等待超时的函数,然后再继续,我尝试使用
jest.useFakeTimers();
jest.advanceTimersByTime(20000);
但我一直收到一条错误信息:
: Timeout - Async callback was not invoked within the 20000 ms timeout specified by jest.setTimeout.Timeout - Async callback was not invoked within the 5000 ms timeout specified by jest.setTimeou
我一直在为使用rsvp承诺的代码编写单元测试。我试图使用pit测试,但没有成功地通过rsvp的测试,尽管嵌入式承诺工作得很好:
//jest.autoMockOff(); - even with this rsvp test is failing
jest.unmock('rsvp');
import rsvp from 'rsvp';
describe('my rsvp tests', () => {
// this test fails
pit('testing rsvp promise', () =>
我正在尝试迁移到的“现代”版本,它不是27.x版本中的默认版本。
我的测试有一些问题,因为Jest一直说像clearTimeout和setInterval这样的函数不是开玩笑的模仿:
// Poster.ts
// This is the class method I'm testing
startInterval(interval = 1800000) {
this._interval && clearTimeout(this._interval)
this._interval = (setInterval(
() =>
this
我已经创建了一个轮询服务,它递归地调用一个api,在api成功的情况下,如果满足了某些条件,就会再次继续轮询。
/**
* start a timer with the interval specified by the user || default interval
* we are using setTimeout and not setinterval because a slow back end server might take more time than our interval time and that would lead to
* a queue o
我试图使用jest来模拟整个对象(ColumnApi来自ag-grid),然后通过参数传递给某个函数,该函数从ColumnApi调用方法"getAllColumns“。我不在乎"getAllColumns“是如何工作的,但我希望它返回一些特定的列数组(Column[])。如何创建此对象/模拟以同时实现:
通过参数将其传递给某个函数,该函数要求该对象的一个函数的ColumnApi类型模拟返回值。
测试:
describe("test", () => {
// my fruitless tries to create the mock / ob