lib/stub.js
// Invokes the user-provided stub `overrideMethod`, else uses the built-in logic.
Invokes the user-provided stub `overrideMethod`, else uses the built-in logic.
Invokes the user - provided stub ` overrideMethod ` else uses the built - in logic .
function stub( objectOrFunction, methodName, overrideMethod ) {
    var args = normalizeArgs(objectOrFunction, methodName, overrideMethod);
    var object = args.ob, methodName = args.me, overrideMethod = args.ov;
    if (overrideMethod && typeof overrideMethod !== 'function' && overrideMethod !== 'stub') throw new Error("override not a function");
    if (overrideMethod == undefined) overrideMethod = 'stub';
    var self = objectOrFunction === object ? object : undefined;
    var context = new QmockStubContext(object, methodName, overrideMethod, self);
    var _spy = object[methodName] = function _spy() {
        var argv = new Array();
        for (var i=0; i<arguments.length; i++) argv[i] = arguments[i];
        return _spy.recordMethod(_spy, _spy._overrideMethod, this, argv);
    }
    for (var k in context) _spy[k] = context[k];
    _spy.stub = _spy;
    return _spy;
}
function stub ( objectOrFunction , methodName , overrideMethod ) { var args = normalizeArgs ( objectOrFunction , methodName , overrideMethod ) ; var object = args . ob , methodName = args . me , overrideMethod = args . ov ; if ( overrideMethod && typeof overrideMethod !== 'function' && overrideMethod !== 'stub' ) throw new Error ( "override not a function" ) ; if ( overrideMethod == undefined ) overrideMethod = 'stub' ; var self = objectOrFunction === object ? object : undefined ; var context = new QmockStubContext ( object , methodName , overrideMethod , self ) ; var _spy = object [ methodName ] = function _spy ( ) { var argv = new Array ( ) ; for ( var i = 0 ; i < arguments . length ; i ++ ) argv [ i ] = arguments [ i ] ; return _spy . recordMethod ( _spy , _spy . _overrideMethod , this , argv ) ; } for ( var k in context ) _spy [ k ] = context [ k ] ; _spy . stub = _spy ; return _spy ; }
Invokes the user-provided stub `overrideMethod`, else uses the built-in logic.
Invokes the user - provided stub ` overrideMethod ` else uses the built - in logic .
// TODO: if function is a constructor, should patch up spy.__proto__ and spy.constructor // intercept calls to the stub to track statistics // copy over the stub context properties and methods // backward compat: make the context available as .stub