@domenic such tool is great idea, but code used for tests is at some points controversial. I think it's good to discuss it further.
Deferred implementation obeys all the concepts that are tested, but when setup, it fails mosts of the tests. Reasons for that are:
Deferred doesn't create extra promise when it doesn't make sense to create one (performance reasons). Following:
promise.then()
Will just return input promise, and tests of this project assume that it should return newly created promise. I don't agree that it's necessary. As you mentioned in your document then
is a mechanism for applying a transformation to a promise. If there's not transformation provided I think it's very ok to return same promise.
In Deferred promise can be rejected only with an error object. It goes also other way, promise cannot be fulfilled with an error object. In result all tests that try to reject promise with some regular value, fail.
In my point of view, rejection should be only about errors, this the reason why it's solved that way in Deferred.
However the way I've solved it, I'm not 100% on now. Thing is in JavaScript we can throw also other objects and I believe it should be matched. So with 0.7 I plan to change behavior so it adheres with throw
, if value can be thrown, we should be able to use it for rejection.
Still I'm wondering: When you work in real world applications, do you reject promises with not error objects? If so what's the case? and if you do, do you also sometimes throw not error objects in synchronous functions (this should go in pair in my opinion)?
In my fork I've updated the tests, so they don't test empty then
calls and do all rejects with errors, then Deferred passes 100%: