Skip to content
This repository has been archived by the owner on Dec 24, 2024. It is now read-only.

Commit

Permalink
feat: add warn alias for warning on the Logger
Browse files Browse the repository at this point in the history
  • Loading branch information
homer0 committed Jul 16, 2020
1 parent 1aef5e5 commit 38cf90c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
8 changes: 7 additions & 1 deletion node/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ class Logger {
* @type {boolean}
*/
this.showTime = showTime;
/**
* An alias for the {@link Logger#warning} method.
*
* @type {Function}
* @see {@link Logger#warning}
*/
this.warn = this.warning.bind(this);
}
/**
* Logs an error (red) message or messages on the console.
Expand Down Expand Up @@ -172,7 +179,6 @@ class Logger {
*
* @param {LoggerMessage} message A single message of a list of them.
* @see {@link Logger#log}
* @todo Add `warn` alias.
*/
warning(message) {
this.log(message, 'yellow');
Expand Down
17 changes: 17 additions & 0 deletions tests/node/logger.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,23 @@ describe('Logger', () => {
expect(colors[color]).toHaveBeenCalledWith(message);
});

it('should log a warning message (yellow) using the `warn` alias', () => {
// Given
const message = 'Something is not working';
const color = 'yellow';
const log = jest.fn();
spyOn(console, 'log').and.callFake(log);
let sut = null;
// When
sut = new Logger();
sut.warn(message);
// Then
expect(log).toHaveBeenCalledTimes(1);
expect(log).toHaveBeenCalledWith(message);
expect(colors[color]).toHaveBeenCalledTimes(1);
expect(colors[color]).toHaveBeenCalledWith(message);
});

it('should log a success message (green)', () => {
// Given
const message = 'Everything works!';
Expand Down

0 comments on commit 38cf90c

Please sign in to comment.