Skip to content

Spying on instance methods #296

Description

@takempf

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...

var next_spy = sinon.spy( player, 'next' );

this happens:

TypeError: Cannot assign to read only property 'next' of #<Object>
    at Object.wrapMethod (C:\Users\Timothy\Repos\sync4\node_modules\sinon\lib\sinon.js:84:30)
    at Object.spy (C:\Users\Timothy\Repos\sync4\node_modules\sinon\lib\sinon\spy.js:228:22)
    at C:\Users\Timothy\Repos\sync4\test\db_room_model.js:102:26
    at C:\Users\Timothy\Repos\sync4\node_modules\orm\lib\Model.js:297:12
    at C:\Users\Timothy\Repos\sync4\node_modules\orm\lib\Singleton.js:32:10
    at Object.<anonymous> (C:\Users\Timothy\Repos\sync4\node_modules\orm\lib\Model.js:112:12)
    at C:\Users\Timothy\Repos\sync4\node_modules\orm\lib\Instance.js:24:7
    at Array.map (native)
    at Instance.emitEvent (C:\Users\Timothy\Repos\sync4\node_modules\orm\lib\Instance.js:23:17)
    at C:\Users\Timothy\Repos\sync4\node_modules\orm\lib\Instance.js:608:4

Is there a recommended method for mocking/spying on instance methods?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions