Is there any way in which I can spy on the bunyan log to ensure I print out what I expect?
MyFile.js
const bunyan = require('bunyan');
const log = bunyan.createLogger({name: 'FailureAuditService'});
class someClass {
someFunct() {
if(x) {
log.warn('something happened');
}
}
}
Test
const service = require(../MyFile);
describe('test something', () => {
it('Will test the bunyan log', res => {
let consoleLog = sinon.spy(log, 'createLogger');
let x = true;
service.someClass(x).then(res => {
let expected = 'something happened';
consoleLog.should.equal(expected);
});
});
})
I worked around this with the following:
const mockReq = require('mock-require);
...
let infoStub = sinon.stub();
let warnStub = sinon.stub();
logStubs = {
info: infoStub,
warn: warnStub
// any other log methods you wish to use
};
mockReq('bunyan', {
createLogger() {
return logStubs;
}
});
...
I then used to mockReq.reRequire() function later on to reset the cache of the service I was wanting to mock.
To assert the actual content of the logs:
let infoLog = infoStub.firstCall.args[0];
let warnLog = warnStub.firstCall.args[0];
With this, I could assert them to equal whatever I expected.
I have heard that JavaScript has a function called search() that can search for a string ( lets call it A ) in another string ( B ) and it will return the first position at which A was found in B. ...
I have heard that JavaScript has a function called search() that can search for a string ( lets call it A ) in another string ( B ) and it will return the first position at which A was found in B. ...
I have an an array with key-value pair, array columns are id and name. I want to sort this array by id. The id column value is of type string type but I want to sort them as numeric values. var ...
I have an an array with key-value pair, array columns are id and name. I want to sort this array by id. The id column value is of type string type but I want to sort them as numeric values. var ...
I'm using Django and Python 3. I have this in my HTML code: {% for category in categories() %} <li class="c-menu__item fs-xsmall"> <a href="#" id="next-category"> ...
I'm using Django and Python 3. I have this in my HTML code: {% for category in categories() %} <li class="c-menu__item fs-xsmall"> <a href="#" id="next-category"> ...
I'm trying to use the panResonder in my React Native app. I tried doing so using class properties instead of constructor and super(). Here is the code: export default class Deck extends Component { ...
I'm trying to use the panResonder in my React Native app. I tried doing so using class properties instead of constructor and super(). Here is the code: export default class Deck extends Component { ...