make isPromise() return boolean value for null and undefined cases
* make isPromise() return boolean value for null and undefined cases
updated as per the review comments
* updated as per review comment
* added a test
@@ -59,8 +59,23 @@ describe('promise', function () {
}
})
- const _assertIsPromise = (p) => assert.ok(promise.isPromise(p))
- const _assertNotPromise = (v) => assert.ok(!promise.isPromise(v))
+ it('isPromise', () => {
+ const v = () => {};
+ const x = new Promise(v, v);
+ const p = createRejectedPromise('reject');
+ const q = Promise.resolve("resolved");
+ assert.equal(true, promise.isPromise(x));
+ assert.equal(true, promise.isPromise(p));
+ assert.equal(true, promise.isPromise(q));
+ assert.equal(false, promise.isPromise(0));
+ assert.equal(false, promise.isPromise(false));
+ assert.equal(false, promise.isPromise(true));
+ assert.equal(false, promise.isPromise(null));
+ assert.equal(false, promise.isPromise(undefined));
+ assert.equal(false, promise.isPromise(''));
+ assert.equal(false, promise.isPromise('promise'));
+ assert.equal(false, promise.isPromise(v));
+ });
function defer() {
let d = {}
