Example #1
0
        it("should return false if given object does not contain a then function", () => {
            var capability = abstract.newPromiseCapability(Promise);

            abstract.updatePromiseFromPotentialThenable(null, capability).should.be.false;
            abstract.updatePromiseFromPotentialThenable(undefined, capability).should.be.false;
            abstract.updatePromiseFromPotentialThenable({}, capability).should.be.false;
            abstract.updatePromiseFromPotentialThenable({ then: {} }, capability).should.be.false;
            abstract.updatePromiseFromPotentialThenable({ then: "flux" }, capability).should.be.false;
        });
Example #2
0
        it("should return true if contains a then function even if it throws", () => {
            var capability = abstract.newPromiseCapability(Promise),
                thenable = {
                    then: () => { throw new Error("this is an error"); }
                };

            abstract.updatePromiseFromPotentialThenable(thenable, capability).should.be.true;
        });
Example #3
0
        it("should return true if contains a then function", () => {
            var capability = abstract.newPromiseCapability(Promise),
                thenable = {
                    then: commonHelpers.noop()
                };

            abstract.updatePromiseFromPotentialThenable(thenable, capability).should.be.true;
        });
Example #4
0
        it("should reject capability if potential then function throws an error", () => {
            var capability = abstract.newPromiseCapability(Promise),
                capabilityRejectStub = sinon.stub(capability, "reject"),
                expectedError = new Error("this is an error"),
                thenable = {
                    then: () => { throw expectedError; }
                };

            abstract.updatePromiseFromPotentialThenable(thenable, capability).should.be.true;
            sinon.assert.calledOnce(capabilityRejectStub);
            sinon.assert.calledWithExactly(capabilityRejectStub, expectedError);
        });