Comments (7)
I don't understand the state === "done"
check enough to comment, really.
from promises-tests.
@ziriax It will probably be hard for us to comment, since we don't understand your code nearly as well as you do. If you could provide some sort of minimal test case that shows a potential problem, such as a particular test not matching a part of the Promises/A+ spec, that'd be extremely helpful.
from promises-tests.
Sorry for not making my question clear enough. I don't understand my own code that much either ;-) I tweaked it until all the specs passed, some of them were really hard to get right.
Let me try to explain my question in detail, with an example.
Consider the following code:
var def1 = deferred();
var prom1 = def1.promise;
var def2 = deferred();
var prom2 = def2.promise;
prom1.then(function (x) {
console.log("done:" + x);
}, function (x) {
console.log("fail:" + x);
});
def1.reject(prom2);
def2.resolve("foo");
What should be the correct output?
If I keep my promise implementation as initially pasted, I get the output:
fail:[object Object]
So prom1
is rejected with prom2
as-is, not doing any further resolution.
However, if I modify my transit
method, removing the state === "done"
check, I get the output
done: foo
In this case prom1
is rejected with prom2
, but prom1
adopts the state of prom2
, so eventually gets fulfilled...
Only one of the two behaviors can be correct, but I don't know which one.
So this means that I have two different implementations, both of them passing all the tests, but with different behavior.
The test suite doesn't seem to dictate the correct behavior, or at least not in the context of my own simple promise implementation.
What confused me in the A+ spec was
2.3.3.3.2: If/when rejectPromise is called with a reason r, reject promise with r.
It's not clear to me what to do when the reason r
is another promise?
Thanks a lot,
Peter Verswyvelen
from promises-tests.
So this means that I have two different implementations, both of them passing all the tests, but with different behavior.
That means you found a bug in the test coverage; nice!
It's not clear to me what to do when the reason r is another promise?
You should follow the spec, and reject promise
with r
.
from promises-tests.
It's not clear to me what to do when the reason r is another promise?
Reject is verbatim. IOW, you shouldn't attempt to resolve r
, but rather use r
as the reason verbatim, even if r
is a promise.
from promises-tests.
jinx again! :)
from promises-tests.
Nice catch!
from promises-tests.
Related Issues (20)
- 2.2.2.2 fails when resolving synchronously outside of .then's event-loop-turn HOT 12
- Help wanted: Own tests or promises-tests tests? HOT 4
- Test suite passes even if clause 2.3.2 is not implemented HOT 1
- Add test case for very nested promises HOT 1
- mocha test runner failures HOT 7
- Add tests for Promise.all and Promise.race. HOT 1
- Can you assist me in satisfying promises aplus spec 2.2.4 in NodeJS? HOT 2
- How to run tests at requirebin?
- "just create a pull request" HOT 2
- Allow to specify the timeout HOT 3
- Promise.prototype.finally tests HOT 1
- resolve then reject miss test case
- 2.3.3 numberOfTimesThenWasRetrieved should not increment in then getter HOT 1
- Please create 1.x branch
- is it still useful? HOT 5
- NPM complains about security issues HOT 1
- RFE: Clarify intent re resolve(promise) HOT 1
- 2.3.3.js `x` is an object with normal Object.prototype
- Error `require`ing adapter file D:\my-promise\my-promise.js HOT 1
- what the purpose of these code is in file 2.1.2.js?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from promises-tests.