首页 > 解决方案 > 如何将 jest.spyOn 与 typescript 命名空间一起使用

问题描述

我想知道如何使用该函数模拟包含在 Typescript 命名空间中的jest.spyOn函数。

例如,如果我有:

// fileA.ts
export namespace helpers {
  export const sayHello = () => console.log('hello')
}
// fileB.ts
import {helpers} from './fileA'

helpers.sayHello()
// fileB.test.ts
import * as helpers from 'fileB.ts'

// I don't know what to put here
const myMock = jest.spyOn(helpers, 'helpers.sayHello')

我如何模拟helpers命名空间中的函数?

标签: jestjs

解决方案


推荐阅读