spec/unit/helpers/spies.js
function mongooseify(obj, returnValues) {

        applyMethods(obj);

        traverse(obj, (key, value) => {
            applyMethods(value);
        });

        function applyMethods(value) {
            if(value && value.hasOwnProperty('_id')) {
                value.toObject = jasmine.createSpy('toObject');
                value.toObject.and.returnValue(JSON.parse(JSON.stringify(value)));
                value.save = jasmine.createSpy('save');
                value.save.and.returnValue(returnValues && returnValues.save ? returnValues.save : Promise.resolve({name : 'fooy'}));
            }
        }
    }
function mongooseify(obj, returnValues) {

        applyMethods(obj);

        traverse(obj, (key, value) => {
            applyMethods(value);
        });

        function applyMethods(value) {
            if(value && value.hasOwnProperty('_id')) {
                value.toObject = jasmine.createSpy('toObject');
                value.toObject.and.returnValue(JSON.parse(JSON.stringify(value)));
                value.save = jasmine.createSpy('save');
                value.save.and.returnValue(returnValues && returnValues.save ? returnValues.save : Promise.resolve({name : 'fooy'}));
            }
        }
    }
function mongooseify ( obj , returnValues ) { applyMethods ( obj ) ; traverse ( obj , ( key , value ) => { applyMethods ( value ) ; } ) ; function applyMethods ( value ) { if ( value && value . hasOwnProperty ( '_id' ) ) { value . toObject = jasmine . createSpy ( 'toObject' ) ; value . toObject . and . returnValue ( JSON . parse ( JSON . stringify ( value ) ) ) ; value . save = jasmine . createSpy ( 'save' ) ; value . save . and . returnValue ( returnValues && returnValues . save ? returnValues . save : Promise . resolve ( { name : 'fooy' } ) ) ; } } }
called with every property and it's value
called with every property and it s value