Whether it's an ES6 Promise or a bluebird Promise, Q Promise, etc.
How do I test to see if a given object is a Promise?
If it has a
.then function - that's the only standard promise libraries use.
The Promises/A+ specification has a notion called
thenable which is basically "an object with a
then method". Promises will and should assimilate anything with a then method. All of the promise implementation you've mentioned do this.
If we look at the specification:
thenis a function, call it with x as this, first argument resolvePromise, and second argument rejectPromise
It also explains the rationale for this design decision:
This treatment of
thenables allows promise implementations to interoperate, as long as they expose a Promises/A+-compliant
thenmethod. It also allows Promises/A+ implementations to “assimilate” nonconformant implementations with reasonable then methods.
You shouldn't - instead call
Q(x) in Q) that will always convert any value or external
thenable into a trusted promise. It is safer and easier than performing these checks yourself.
You can always run it through the test suite :D