Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checks 2nd parameter of the notify() method to be a function #138

Merged
merged 1 commit into from
Sep 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ module.exports.mapToMac = function (options) {
module.exports.actionJackerDecorator = function (emitter, options, fn, mapper) {
options = clone(options);
fn = fn || function (err, data) {};

if (typeof fn !== "function")
throw new TypeError('The second argument must be a function callback. You have passed '+ typeof fn);

return function (err, data) {

var resultantData = data;
Expand Down
3 changes: 3 additions & 0 deletions notifiers/notifysend.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ NotifySend.prototype.notify = function (options, callback) {
options = cloneDeep(options || {});
callback = callback || function () {};

if (typeof callback !== "function")
throw new TypeError('The second argument must be a function callback. You have passed '+ typeof callback);

if (typeof options === 'string') options = {
title: 'node-notifier',
message: options
Expand Down
16 changes: 16 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,22 @@ describe('constructors', function(){
should(notifier.notify).be.ok;
});

it('should expect only a function callback as second parameter', function () {
var cb = function (err, data) {};
var data = { 'title': 'My notification' };

should(notifier.notify(data, cb)).be.ok;
});

it('should throw error when second parameter is not a function', function () {
var wrongParamOne = 200;
var wrongParamTwo = 'meaningless string';
var data = { 'title': 'My notification' };

notifier.notify.bind(notifier, data, wrongParamOne).should.throw(/^The second argument/);
notifier.notify.bind(notifier, data, wrongParamTwo).should.throw(/^The second argument/);
});

it('should expose a default selected constructor function', function () {
should(notifier instanceof notifier.Notification).be.ok;
});
Expand Down