-
Notifications
You must be signed in to change notification settings - Fork 376
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
Spying on instance methods #296
Comments
What exactly is |
For what it's worth... Room.Player = Room.extendsTo( 'player', {
elapsed: {
type: 'number',
defaultValue: 0
},
duration: Number,
order: {
type: 'enum',
values: ['normal','shuffle'],
defaultValue: 'normal'
}
}, {
// TODO use this instead -> autoFetch: true,
hooks: {
afterLoad: function(){
// TODO see if this can be mixed in to the instance
if( !this.events ) this.events = new EventEmitter;
this.timer;
}
},
methods: {
// select and play the next item
next: function( cb ){
cb = cb || function(){};
var player = this;
player.getRoom( function( err, room ){
if( err ) return cb( err );
room.getItems( function( err, items ){
if( err ) return cb( err );
if( items.length === 0 ){
player.load( null, function( err ){
if( err ) return cb( err );
return cb();
});
return;
}
var item;
if( player.order === 'normal' ) item = items[0];
if( player.order === 'shuffle' ) item = items[ _.random( items.length ) ];
room.removePlaylistItem( item.id, function( err ){
if( err ) return cb( err );
player.load( item, function( err ){
if( err ) return cb( err );
return cb();
});
});
});
});
},
...
},
reverse: 'room'
}); |
I'm not sure if the |
I think this is because of this line: https://github.com/dresende/node-orm2/blob/master/lib/Instance.js#L457 It defines the methods not specifying for (k in opts.methods) {
Object.defineProperty(instance, k, {
value: opts.methods[k].bind(instance),
enumerable: false,
configurable: true
});
} If it works I'll update it. I don't want to touch the repository now since I'm waiting for some changes from a fork and don't want to cause conflicts. |
It might be the |
If you still want this and the above change works please reopen and I'll change it. |
@dresende the |
Inside some of my tests I've found that I need to spy on instance methods, but it seems that it's impossible at present since these are read only properties. When I try to use sinon's spy method...
this happens:
Is there a recommended method for mocking/spying on instance methods?
The text was updated successfully, but these errors were encountered: