I'm writing nodejs module for learning purposes (logging service) and I have problem with testing part of the code.
Shortened version of code I want to test is (whole project HERE):
var tupelo = exports;
var logMessage = function(debugLevel, color, message) {
var time = new Date().toISOString();
console.log(
color(debugLevel + ' on ' + time + '| ' + message)
);
}
tupelo.verbose = function(message) {
if (levelEnabled('VERBOSE')) {
logMessage('VERBOSE', colors.gray, message);
}
}
I'd like to test if logMessage was called based on return value of levelEnabled('VERBOSE') (true / false)
Because it is a private method, I found that I can access it from my spec with rewire
var rewire = require('rewire');
var tupelo = rewire('../src/tupelo');
describe(' displays logs only on enabled levels', function() {
it('should display all logs below or equal to debugLevel', function() {
var logMessage = tupelo.__get__('logMessage');
spyOn(tupelo, 'logMessage');
debugLevel = 'VERBOSE';
tupelo.verbose('testing')
expect(tupelo.logMessage).toHaveBeenCalled();
});
});
Except it doesn't work. Error jasmine returns is:
Error: logMessage() method does not exist
I'm obviously not aware of something that I probably should be. How can I properly test that? What am I missing?
Aucun commentaire:
Enregistrer un commentaire