javascript - ViTest Mock is not replacing function - Stack Overflow

For some reason in ViTest mocks are not replacing my real function. I have a main function hereconst {

For some reason in ViTest mocks are not replacing my real function. I have a main function here

const { handler1 } = require(./path/handler1)

exports.mainFunction = async (event) => {
 try {
    const val1 = await handler1(event)
    console.log(val1)

Handler 1 looks like

exports.handler1 = async (data) => { return "real" }

I am trying to write unit tests for mainFunction where I can mock the response from handler1 (Handler1 already has its own unit tests)

import { handler1} from '../path/handler1.js';
vi.mock('../path/handler1.js');

describe('mainFunction()', function () {
  it("should return fake")  async function () {
    let handlerMock = {
      handler1: () => "Fake",
    };
    handler1.mockResolvedValue(handlerMock);
    await mainFunction("event")
    // mainFunction is outputting real and not fake

  }
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744180161a4561941.html

相关推荐

  • javascript - ViTest Mock is not replacing function - Stack Overflow

    For some reason in ViTest mocks are not replacing my real function. I have a main function hereconst {

    9天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信