{"action":"created","issue":{"url":"https://api.github.com/repos/speedskater/babel-plugin-rewire/issues/45","labels_url":"https://api.github.com/repos/speedskater/babel-plugin-rewire/issues/45/labels{/name}","comments_url":"https://api.github.com/repos/speedskater/babel-plugin-rewire/issues/45/comments","events_url":"https://api.github.com/repos/speedskater/babel-plugin-rewire/issues/45/events","html_url":"https://github.com/speedskater/babel-plugin-rewire/issues/45","id":103457517,"number":45,"title":"Cannot rewire instance methods","user":{"login":"valermor","id":2091621,"avatar_url":"https://avatars.githubusercontent.com/u/2091621?v=3","gravatar_id":"","url":"https://api.github.com/users/valermor","html_url":"https://github.com/valermor","followers_url":"https://api.github.com/users/valermor/followers","following_url":"https://api.github.com/users/valermor/following{/other_user}","gists_url":"https://api.github.com/users/valermor/gists{/gist_id}","starred_url":"https://api.github.com/users/valermor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/valermor/subscriptions","organizations_url":"https://api.github.com/users/valermor/orgs","repos_url":"https://api.github.com/users/valermor/repos","events_url":"https://api.github.com/users/valermor/events{/privacy}","received_events_url":"https://api.github.com/users/valermor/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-08-27T08:43:49Z","updated_at":"2015-09-01T16:58:53Z","closed_at":null,"body":"Rewiring static methods works ok. I am getting an issue when trying to rewire instance methods.\r\n\r\nExample:\r\n\r\nmodule _aclass.es6_:\r\n```javascript\r\nimport { BClass } from './bclass.es6';\r\nclass AClass {\r\n    constructor() {\r\n        this.bValue = BClass.aStaticMethod();\r\n    }\r\n    getBValue() {\r\n        return this.bValue;\r\n    }\r\n    getBName() {\r\n        return new BClass().getName();\r\n    }\r\n}\r\nexport { AClass };\r\n```\r\n\r\nmodule _bclass.es6_:\r\n```javascript\r\nclass BClass {\r\n    constructor() {\r\n        this.name = 'B';\r\n    }\r\n    getName() {\r\n        return this.name;\r\n    }\r\n    static aStaticMethod() {\r\n        return 'static';\r\n    }\r\n}\r\nexport { BClass };\r\n```\r\n\r\nand the tests:\r\n```javascript\r\nimport { AClass, __Rewire__ } from './aclass.es6';\r\ndescribe('Test for rewiring dependencies of a class', function() {\r\n    __Rewire__('BClass', {\r\n        aStaticMethod: () => 'rewired static',\r\n        getName: () => 'rewired getName'\r\n    });\r\n    it('should rewire a static method', function() {\r\n        let theClass = new AClass();\r\n\r\n        theClass.getBValue().should.equal('rewired static');\r\n    });\r\n    it('should rewire an instance method', function() {\r\n        let theClass = new AClass();\r\n        theClass.getBName().should.equal('rewired getName');\r\n    })\r\n});\r\n```\r\n\r\n  Test for rewiring dependencies of a class\r\n    ✓ should rewire a static method\r\n    1) should rewire an instance method\r\n\r\n  1) Test for rewiring dependencies of a class should rewire an instance method:\r\n     TypeError: object is not a function\r\n      at AClass.getBName (test/aclass.es6:14:16)\r\n      at Context.<anonymous> (test/rewire-dependent-class.es6:21:18)\r\n\r\nIs this case supported at all?"},"comment":{"url":"https://api.github.com/repos/speedskater/babel-plugin-rewire/issues/comments/136794821","html_url":"https://github.com/speedskater/babel-plugin-rewire/issues/45#issuecomment-136794821","issue_url":"https://api.github.com/repos/speedskater/babel-plugin-rewire/issues/45","id":136794821,"user":{"login":"TheSavior","id":249164,"avatar_url":"https://avatars.githubusercontent.com/u/249164?v=3","gravatar_id":"","url":"https://api.github.com/users/TheSavior","html_url":"https://github.com/TheSavior","followers_url":"https://api.github.com/users/TheSavior/followers","following_url":"https://api.github.com/users/TheSavior/following{/other_user}","gists_url":"https://api.github.com/users/TheSavior/gists{/gist_id}","starred_url":"https://api.github.com/users/TheSavior/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TheSavior/subscriptions","organizations_url":"https://api.github.com/users/TheSavior/orgs","repos_url":"https://api.github.com/users/TheSavior/repos","events_url":"https://api.github.com/users/TheSavior/events{/privacy}","received_events_url":"https://api.github.com/users/TheSavior/received_events","type":"User","site_admin":false},"created_at":"2015-09-01T16:58:53Z","updated_at":"2015-09-01T16:58:53Z","body":"You don't need rewire for this, you can just get the reference to your Class in your test and overwrite the function on the prototype. The value of rewire (and its family of packages) is to modify private state in modules that you would be otherwise unable to access. \r\n\r\nRewire should be the base package that simply enables private state and then lets other packages be built on top of it. That is why it is also important to not have this package diverge in any meaningful way from the standard rewire. Packages built on top of rewire should work with rewire, rewireify, rewire-global, and babel-plugin-rewire with no differences."}}