Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/408.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 正在调用Jest Mock函数,但expect.toHaveBeenCalled仍然失败_Javascript_Typescript_Testing_Jestjs - Fatal编程技术网

Javascript 正在调用Jest Mock函数,但expect.toHaveBeenCalled仍然失败

Javascript 正在调用Jest Mock函数,但expect.toHaveBeenCalled仍然失败,javascript,typescript,testing,jestjs,Javascript,Typescript,Testing,Jestjs,以下测试的结果失败: 预期呼叫数:>=1 收到的呼叫数:0 即使调用了模拟函数,测试仍失败。在我的日志中,console.log('event wrapper')实际上也显示console.log('this mock function's called'),因此我不理解为什么行expect(eventWrapper.client.createChannel).tohavebeencall()仍然失败 功能定义如下: 模拟功能: // eventWrapper.ts export const

以下测试的结果失败: 预期呼叫数:>=1 收到的呼叫数:0

即使调用了模拟函数,测试仍失败。在我的日志中,console.log('event wrapper')实际上也显示console.log('this mock function's called'),因此我不理解为什么行
expect(eventWrapper.client.createChannel).tohavebeencall()仍然失败

功能定义如下: 模拟功能:

 // eventWrapper.ts
 export const eventWrapper = {
   client: {
    createChannel: jest
      .fn()
      .mockImplementation(() => {
        console.log('event wrapper');
        return { 
          assertQueue: () => console.log('this mock function is being called'),
          sendToQueue: jest.fn()
        }
      }),
   }
 };

// test.ts
// POST /api/tickets is successful, its also the one who trigger/call the event wrapper
jest.mock('../../events/EventWrapper');
it('should publish an event after successful creation of tickets', async (done) => {
    await request(app).post('/api/tickets').send({
      title: 'string',
      price: 23,
      userId: 'stringdsa',
    }).expect(201);
    expect(eventWrapper.client.createChannel).toHaveBeenCalled();
  });