【发布时间】:2020-12-30 22:17:06
【问题描述】:
我必须模拟一个内部调用的函数,但我正在测试的函数是使用 typescript 中的命名导出导出的。
import { internalFunc } from './internal.ts';
const funcToTest = () => {
internalFunc(); // I need to mock this function
}
export {
funcToTest
}
现在我的测试文件是这样的,
import { describe } from 'mocha';
import { expect } from 'chai';
import sinon from 'sinon';
import { funcToTest } from './myModule.ts';
describe ('something meaningful', () => {
it ('should pass', () => {
sinon.stub(); // I'm stuck here. How do I mock this internalFunc()?
let result = funcToTest();
}
}
您能否建议一种模拟internalFunc() 方法的方法?
【问题讨论】:
标签: javascript typescript unit-testing mocha.js sinon