cjohansen/Sinon.JS — Issue #87: Stub/Spies direct onto an Object
Author: quangv
Created: 2012-02-28 05:11:17+00:00
State: open

Hi, I'm kind of new to BDD/TDD, Sinon.js is great btw :)

I'm using Sinon.js with [Mocha](https://github.com/visionmedia/mocha) & Node.js, and I was wondering if there was a way to add spies/stubs onto existing objects... so that any reference to that object now includes those spies... for example...

_module.js_

```
module.exports = function(){
}
```

_subject.js_

```
x = require('./module.js');
x()
```

_test_subject.js_

```javascript
describe('subject', function(){
it('should call x()', function(){
x = require('./module.js');
sinon.spy(x);
require('./subject.js');
assert.equal(x.called, true);
});
})
```

might not be possible, thanks :)