Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.2.6.2 wrong test? #58

Closed
ziriax opened this issue Apr 6, 2014 · 3 comments
Closed

2.2.6.2 wrong test? #58

ziriax opened this issue Apr 6, 2014 · 3 comments

Comments

@ziriax
Copy link

ziriax commented Apr 6, 2014

I might be wrong, but shouldn't this test:

        describe("results in multiple branching chains with their own fulfillment values", function () {
            testRejected(sentinel, function (promise, done) {
                var semiDone = callbackAggregator(3, done);

                promise.then(null, function () {
                    return sentinel;
                }).then(function (value) {
                    assert.strictEqual(value, sentinel);
                    semiDone();
                });

                promise.then(null, function () {
                    throw sentinel2;
                }).then(null, function (reason) {
                    assert.strictEqual(reason, sentinel2);
                    semiDone();
                });

                promise.then(null, function () {
                    return sentinel3;
                }).then(function (value) {
                    assert.strictEqual(value, sentinel3);
                    semiDone();
                });
            });
        });

be

        describe("results in multiple branching chains with their own fulfillment values", function () {
            testRejected(sentinel, function (promise, done) {
                var semiDone = callbackAggregator(3, done);

                promise.then(null, function () {
                    return sentinel;
                }).then(null, function (value) {
                    assert.strictEqual(value, sentinel);
                    semiDone();
                });

                promise.then(null, function () {
                    throw sentinel2;
                }).then(null, function (reason) {
                    assert.strictEqual(reason, sentinel2);
                    semiDone();
                });

                promise.then(null, function () {
                    return sentinel3;
                }).then(null, function (value) {
                    assert.strictEqual(value, sentinel3);
                    semiDone();
                });
            });
        });

@domenic
Copy link
Member

domenic commented Apr 7, 2014

Nope; since we return from the rejection handler, the promise will be fulfilled, not rejected.

@domenic domenic closed this as completed Apr 7, 2014
@ziriax
Copy link
Author

ziriax commented Apr 7, 2014

Interesting. So rejecting with a new 'error' results in a fulfilled promise? So this models

try {
}
catch(e) {
return newValue;
}

That makes sense. But how would one model:

try {
}
catch(e) {
throw new MyError(e);
}

One would need to return a new rejected promise I guess? Or just throw the MyError(e) in the rejection handler?

@ziriax
Copy link
Author

ziriax commented Apr 7, 2014

Ah I see you test indeed checks the throw case. These tests are really great! Nice work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants