index.js
function (resolved, val) {
                var should = (negate ?
                    (new Assertion(val)).not :
                    (new Assertion(val))
                );
                
                if (storedAssertions[0][0] !== 'throw' && !resolved) {
                    throw val;
                }
                
                var result = storedAssertions.reduce(function (accum, cur) {
                    // 'throw' must immediately follow 'eventually' if it is used
                    if (cur[0] === 'throw') {
                        // should.throw is a special case; it expects a function
                        // that it will then call to discern whether an error was thrown
                        // or not, but we have a (potentially) rejected value of a promise,
                        // so we need to wrap that value in a function for should.throw to call
                        var obj = accum.obj;
                        accum.obj = function () {
                            if (resolved) { return obj; }
                            else { throw obj; }
                        };
                    }
                    
                    // this block is separated from the above intentionally;
                    // the above deals with putting the data in the expected format,
                    // while this deals with whether or not to throw an error
                    if (cur[0] === 'throw') {
                        // these conditions are acceptable:
                        // resolved === true && negate === true - promise succeeded, throw check is negated
                        // resolved === false && negate !== true - promise rejected, throw check is not negated
                        if (resolved === !!accum.negate) {
                            caught = true;
                        } else {
                            throw new AssertionError({
                                message: 'Expected promise to be ' + (negate ? 'resolved' : 'rejected') +
                                    ' but instead it was ' + (resolved ? 'resolved' : 'rejected') + ' with ' + inspect(val),
                                actual: val
                            });
                        }
                    }
                    
                    if (cur.length === 1) {
                        // assertion was a getter, apply to current value
                        return accum[cur[0]];
                    } else {
                        // assertion was a function, apply to current value
                        return accum[cur[0]].apply(accum, cur[1]);
                    }
                }, should); // call .should on our resolved value to begin the assertion chain
                
                if (!resolved && !caught) {
                    throw new AssertionError({
                        message: 'Promise was rejected unexpectedly with ' + inspect(val),
                        actual: val
                    });
                }
                return result;
            }
function (resolved, val) {
                var should = (negate ?
                    (new Assertion(val)).not :
                    (new Assertion(val))
                );
                
                if (storedAssertions[0][0] !== 'throw' && !resolved) {
                    throw val;
                }
                
                var result = storedAssertions.reduce(function (accum, cur) {
                    // 'throw' must immediately follow 'eventually' if it is used
                    if (cur[0] === 'throw') {
                        // should.throw is a special case; it expects a function
                        // that it will then call to discern whether an error was thrown
                        // or not, but we have a (potentially) rejected value of a promise,
                        // so we need to wrap that value in a function for should.throw to call
                        var obj = accum.obj;
                        accum.obj = function () {
                            if (resolved) { return obj; }
                            else { throw obj; }
                        };
                    }
                    
                    // this block is separated from the above intentionally;
                    // the above deals with putting the data in the expected format,
                    // while this deals with whether or not to throw an error
                    if (cur[0] === 'throw') {
                        // these conditions are acceptable:
                        // resolved === true && negate === true - promise succeeded, throw check is negated
                        // resolved === false && negate !== true - promise rejected, throw check is not negated
                        if (resolved === !!accum.negate) {
                            caught = true;
                        } else {
                            throw new AssertionError({
                                message: 'Expected promise to be ' + (negate ? 'resolved' : 'rejected') +
                                    ' but instead it was ' + (resolved ? 'resolved' : 'rejected') + ' with ' + inspect(val),
                                actual: val
                            });
                        }
                    }
                    
                    if (cur.length === 1) {
                        // assertion was a getter, apply to current value
                        return accum[cur[0]];
                    } else {
                        // assertion was a function, apply to current value
                        return accum[cur[0]].apply(accum, cur[1]);
                    }
                }, should); // call .should on our resolved value to begin the assertion chain
                
                if (!resolved && !caught) {
                    throw new AssertionError({
                        message: 'Promise was rejected unexpectedly with ' + inspect(val),
                        actual: val
                    });
                }
                return result;
            }
function ( resolved , val ) { var should = ( negate ? ( new Assertion ( val ) ) . not : ( new Assertion ( val ) ) ) ; if ( storedAssertions [ 0 ] [ 0 ] !== 'throw' && ! resolved ) { throw val ; } var result = storedAssertions . reduce ( function ( accum , cur ) { // 'throw' must immediately follow 'eventually' if it is used if ( cur [ 0 ] === 'throw' ) { // should.throw is a special case; it expects a function // that it will then call to discern whether an error was thrown // or not, but we have a (potentially) rejected value of a promise, // so we need to wrap that value in a function for should.throw to call var obj = accum . obj ; accum . obj = function ( ) { if ( resolved ) { return obj ; } else { throw obj ; } } ; } // this block is separated from the above intentionally; // the above deals with putting the data in the expected format, // while this deals with whether or not to throw an error if ( cur [ 0 ] === 'throw' ) { // these conditions are acceptable: // resolved === true && negate === true - promise succeeded, throw check is negated // resolved === false && negate !== true - promise rejected, throw check is not negated if ( resolved === ! ! accum . negate ) { caught = true ; } else { throw new AssertionError ( { message : 'Expected promise to be ' + ( negate ? 'resolved' : 'rejected' ) + ' but instead it was ' + ( resolved ? 'resolved' : 'rejected' ) + ' with ' + inspect ( val ) , actual : val } ) ; } } if ( cur . length === 1 ) { // assertion was a getter, apply to current value return accum [ cur [ 0 ] ] ; } else { // assertion was a function, apply to current value return accum [ cur [ 0 ] ] . apply ( accum , cur [ 1 ] ) ; } } , should ) ; // call .should on our resolved value to begin the assertion chain if ( ! resolved && ! caught ) { throw new AssertionError ( { message : 'Promise was rejected unexpectedly with ' + inspect ( val ) , actual : val } ) ; } return result ; }
this function will kick off the new chain of assertions on the setttled result of the promise
this function will kick off the new chain of assertions on the setttled result of the promise