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

Commit

Permalink
make isPromise support null as a parameter (mochajs#3518)
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiosantoscode authored and boneskull committed Dec 11, 2018
1 parent 7cfbd0d commit e44b9b4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,11 @@ exports.stackTraceFilter = function() {
* @returns {boolean} Whether or not `value` is a Promise
*/
exports.isPromise = function isPromise(value) {
return typeof value === 'object' && typeof value.then === 'function';
return (
typeof value === 'object' &&
value !== null &&
typeof value.then === 'function'
);
};

/**
Expand Down
4 changes: 4 additions & 0 deletions test/unit/utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,10 @@ describe('lib/utils', function() {
it('should return false if the value is an object w/o a "then" function', function() {
expect(utils.isPromise({}), 'to be', false);
});

it('should return false if the object is null', function() {
expect(utils.isPromise(null), 'to be', false);
});
});

describe('escape', function() {
Expand Down

0 comments on commit e44b9b4

Please sign in to comment.