Unit testing sinon间谍模块导出新类
我在node.js中使用mocha和sinon进行单元测试。我有一个模仿谷歌认证库的问题。这是需要测试的代码的一部分:Unit testing sinon间谍模块导出新类,unit-testing,mocha.js,sinon,Unit Testing,Mocha.js,Sinon,我在node.js中使用mocha和sinon进行单元测试。我有一个模仿谷歌认证库的问题。这是需要测试的代码的一部分: const GoogleAuth = require('google-auth-library'); const auth = new GoogleAuth(); const oauth2Client = new auth.OAuth2(clientId, clientSecret, redirectUrl); 我正在尝试测试“new GoogleAuth()”和OAuth2
const GoogleAuth = require('google-auth-library');
const auth = new GoogleAuth();
const oauth2Client = new auth.OAuth2(clientId, clientSecret, redirectUrl);
我正在尝试测试“new GoogleAuth()”和OAuth2,但没有任何效果。
这是我的嘲弄:
let googleMock = sinon.stub().returns({
Oauth2: sinon.spy()
});
....
it('should call new GoogleAuth', function ()
{
expect(googleMock).calledWithNew();
});
错误:预期已调用存根,新问题已解决,如下所示:
let OAuth2Mock = sinon.stub();
let googleMock = sinon.spy(function ()
{ return { OAuth2: OAuth2Mock } } );