https://github.com/chinchiheather/chai-spies-augment
Additions to the chai-spies library, adds ability to inspect the parameters a spy has been called with and ability to check if a spy was called with a partial object
https://github.com/chinchiheather/chai-spies-augment
chai chai-spies javascript unit-testing
Last synced: 4 months ago
JSON representation
Additions to the chai-spies library, adds ability to inspect the parameters a spy has been called with and ability to check if a spy was called with a partial object
- Host: GitHub
- URL: https://github.com/chinchiheather/chai-spies-augment
- Owner: chinchiheather
- Created: 2018-03-04T04:58:55.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-03-18T07:07:47.000Z (about 7 years ago)
- Last Synced: 2024-04-26T14:05:00.095Z (about 1 year ago)
- Topics: chai, chai-spies, javascript, unit-testing
- Language: JavaScript
- Homepage:
- Size: 14.6 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# chai-spies-augment
Additions to the [chai-spies](https://github.com/chaijs/chai-spies) libraryAdds:
* Ability to easily inspect the parameters a spy has been called with
* Ability to check if a spy was called with a partial object## Install
```bash
npm install --save-dev chai-spies-augment
```Then in your test setup file where you are loading chai spies
```js
import chaiSpies from 'chai-spies';
import chaiSpiesAugment from 'chai-spies-augment';
...
chai.use(chaiSpies);
chai.use(chaiSpiesAugment);
```## Usage
### Accessing spy call parameters
```js
const spy = chai.spy();
spy(1, 2, 3);
spy('a', 'b', 'c');
const args = spy.args(); // ['a', 'b', 'c']
const argsFor = spy.argsFor(0); // [1, 2, 3]
```
### Checking for partial object```js
const spy = chai.spy();
spy({ a: 'b', c: 'd' });
spy(1, 'a', { b: 'c' });
expect(spy).to.have.been.called.with.objectContaining({ a: 'b' }); // true
expect(spy).to.have.been.called.with.objectContaining({ b: 'c' }); // true
```