我有一个有趣的 ES6 函数/对象。
我希望能够监视和嘲笑这个:
export const floppyDisk = someInitiateFunction()
// it has a constructor/default function and is used like this.
// - I want to spy on this 'default/constructor' function
export const someVariableConnection = floppyDisk('initiate url')
// but, floppyDisk can also be used like this: ( I want to spy on these also )
// - I think this '.helpers' sub object is part of the prototype? Not sure.
const insertQuery = floppyDisk.helpers.insert(arg, arg2, arg3)
const updateQuery = floppyDisk.helpers.update(arg, arg2, arg3)
我尝试模拟 someInitiateFunction
返回一个对象,__esModule: true
带有 default: jest.fn()
,并使用带有构造函数的假类,但我无法得到任何工作。
关于如何模拟这样一个简单但奇怪的对象有什么想法吗?