https://github.com/xpl/chai-spies-decorators
Chai Spies + ES7 decorators
https://github.com/xpl/chai-spies-decorators
Last synced: 10 months ago
JSON representation
Chai Spies + ES7 decorators
- Host: GitHub
- URL: https://github.com/xpl/chai-spies-decorators
- Owner: xpl
- License: unlicense
- Created: 2016-08-18T05:52:25.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2017-05-26T10:12:03.000Z (about 9 years ago)
- Last Synced: 2025-06-14T05:03:26.625Z (about 1 year ago)
- Language: JavaScript
- Size: 8.79 KB
- Stars: 4
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# chai-spies-decorators
```bash
npm install chai-spies-decorators
```
Provides ES7 decorators interface for [`chai-spies`](https://github.com/chaijs/chai-spies), allowing to set execution contracts on class methods in a nice declarative way. Requires [Mocha](https://mochajs.org/).
```javascript
import 'chai-spies-decorators'
describe ('example', () => {
it ('works', () => {
const foo = new (class Foo {
@will.have.been.called.with (42).once
bar () { }
@will.have.been.called.twice
zap () { }
})
foo.bar (42)
foo.zap (); foo.zap ()
})
})
```
## How it works
I've written an article on Medium explaining it: [Wiring ES7 decorators to Chai Spies for declarative contracts on class methods: A metaprogramming case study](https://medium.com/@xpl/wiring-es7-decorators-to-chai-spies-for-declarative-contracts-on-class-methods-957d6a8c27e9#.30sh22os4).
## Warning
It is not very well tested with asynchronous tests. Should work with Promises, but not with `done` callback (not implemented).