☕️ Classic, reliable, trusted test framework for Node.js and the browser
make isPromise support null as a parameter (#3518)
Fábio Santosf9a6f9b908c2
diff --git a/lib/utils.js b/lib/utils.jsindex bb0fa355..dbcbbc2b 100644--- a/lib/utils.js+++ b/lib/utils.js@@ -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'+ );};/**diff --git a/test/unit/utils.spec.js b/test/unit/utils.spec.jsindex e5a68deb..aaed6709 100644--- a/test/unit/utils.spec.js+++ b/test/unit/utils.spec.js@@ -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() {