Decorator make modules in ECMAScript 2015+ stubbable
npm install stubbable-decoratorA decorator to make possible to stub modules in ECMAScript 2015+.
```
npm install -S stubbable-decorator
`js
//
// Module declaration
//
import stubbable from 'stubbable-decorator'
class Foo {
constructor(bar) {
this.bar = bar
}
}
export default stubbable(Foo)
`
`js
//
// Testing
//
Foo.stub = sinon.stub().returns({})
const obj = new Foo()
expect(VHS.api.Poller.stub).calledOnce // 👍
`
`js
//
// Module declaration
//
import stubbable from 'stubbable-decorator'
function foo() { return 123 }
export default stubbable(foo)
`
`js
//
// Testing
//
foo.stub = sinon.stub().returns(321)
const result = foo()
expect(result).to.be.equal(321) // 👍
`
In the current spec it is only possible to decorate classes and classes
properties.
`js
//
// Module declaration
//
import stubbable from 'stubbable-decorator'
@stubbable
class Foo {
constructor(bar) {
this.bar = bar
}
}
export default Foo
`
`js
//
// Testing
//
Foo.stub = sinon.stub().returns({})
const obj = new Foo()
expect(VHS.api.Poller.stub).calledOnce // 👍
``
---
caiogondim.com ·
GitHub @caiogondim ·
Twitter @caio_gondim