我正在尝试使用 proxyquire 测试对象。该对象是一个简单的 JavaScript / TypeScript 类,具有一些依赖项。我正在使用带有 sinon 的 proxyquire 来覆盖这些依赖项,并且工作正常。但我无法创建该类的新实例来在测试程序上运行它的方法。
我试图在返回新实例的类上创建一个静态方法,但错误是“Proxy.create is not a function”
// a stub of one of the dependents in
const poolRepositoryStub = {
insert: _.constant({}),
'@noCallThru': true,
};
const Proxy = proxyquire('../../dist/src/components/proxy.js', {
'../repository/pool-repository': poolRepositoryStub,
'@noCallThru': true,
});
describe('Test ReportCheckComponent', () => {
before(() => {
// this one failed say Proxy is not a constructor
new Proxy()
// and this one also failed on Proxy.create is not a function
Proxy.create();
});
it('report-check.spec.ts: test run method using sinon stub', () => {
sinon
.stub(poolRepositoryStub, 'insert')
.returns(Promise.resolve(null))
// ... the rest of the test code
});
});