Skip to content

Commit 224949f

Browse files
committed
Adjust the way ParsePromise.is detects thenables
1 parent 3110db0 commit 224949f

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/ParsePromise.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ export default class ParsePromise {
283283
*/
284284
static is(promise) {
285285
return (
286-
typeof promise !== 'undefined' &&
286+
promise != null &&
287287
typeof promise.then === 'function'
288288
);
289289
}

src/__tests__/ParsePromise-test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,4 +422,13 @@ describe('Promise', () => {
422422
expect(error).toBe('hello');
423423
});
424424
});
425+
426+
it('can check if an object is a thenable promise', () => {
427+
expect(ParsePromise.is(null)).toBe(false);
428+
expect(ParsePromise.is(void(0))).toBe(false);
429+
expect(ParsePromise.is('a string')).toBe(false);
430+
expect(ParsePromise.is({})).toBe(false);
431+
expect(ParsePromise.is(ParsePromise.as())).toBe(true);
432+
expect(ParsePromise.is(ParsePromise.error())).toBe(true);
433+
})
425434
});

0 commit comments

Comments
 (0)