Okay, new problem.
foo.js
const doFoo = () => { console.log('bad stuff!') }
const doBar = () => { doFoo() }
module.exports = { doFoo, doBar }
foo.test.js
const sandbox = require('sinon').sandbox.create()
const foo = require('./foo')
describe('doBar', () => {
before(() => {
sandbox.stub(foo, 'doFoo')
})
it('should call doFoo', () => {
foo.doBar() // prints "doFoo" to console
})
})
What gives? Why isn't doFoo
mocked when doBar
calls it?
doFoo
before doBar
is defined.sandbox.stub(console, 'log');
.
const aSpy = sinon.spy(object, 'method');
aSpy.wasCalled(function() {
//....do some stuff after the spied method was called
})
.callsFake()
I have a problem with undefined methods on mock
My test code looks like this:
const mock = sinon.mock(new Xxx(configuration));
mock.expects('methodA').once().withArgs(sessionId, '', '', '', null).resolves(null);
new ClassUnderTest(mock, 100);
ClassUnderTest calls arg1.methodA(); and fails with TypeError: arg1.methodA is not a function
How can I mock this 'getQbo' function ?
Have this library
// quickbooks module.ts
var QuickBooks = require('node-quickbooks');
export function getQbo (token, companyId, refresh) {
return new QuickBooks(process.env.QB_CLIENT_ID,
process.env.QB_CLIENT_SECRET,
token, /* oAuth access token */
false, /* no token secret for oAuth 2.0 */
companyId,
true, /* use a sandbox account */
true, /* turn debugging on */
4, /* minor version */
'2.0', /* oauth version */
refresh /* refresh token */);
}
Imported like this
// paymetn.module.ts
import {getQbo} from "./../../../utils/quickBooks/qbo.module";
var mock = sinon.mock(QuickBooks);
var stub = sinon.stub(QuickBooks, “getQbo”);
var mock = sinon.mock(getQbo);
var stub = sinon.stub(getQbo, “getQbo”);
response
calls, I've tried to call it with .call
and .apply
to set what this
should be, and a number of other things, but this
is always {}
inside the intent object
this
inside that object so I can test if they're called?
const handlers = {
'HelloWorldIntent' : function() {
//emit response directly
this.emit(':tell', 'Hello World!');
}
};