https://github.com/jamonserrano/karma-calling
Karma plugin to test function parameters and errors in BDD-style assertions
https://github.com/jamonserrano/karma-calling
bdd-style functions karma parameters testing
Last synced: 10 months ago
JSON representation
Karma plugin to test function parameters and errors in BDD-style assertions
- Host: GitHub
- URL: https://github.com/jamonserrano/karma-calling
- Owner: jamonserrano
- License: mit
- Created: 2016-04-03T17:35:18.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2016-11-24T16:09:31.000Z (about 9 years ago)
- Last Synced: 2025-03-03T17:04:22.556Z (10 months ago)
- Topics: bdd-style, functions, karma, parameters, testing
- Language: JavaScript
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# karma-calling
Test function parameters and errors in BDD-style assertions
Based on http://stackoverflow.com/a/34590246
## Installation
1\. Install the plugin from npm:
```sh
$ npm install karma-calling --save-dev
```
2\. Add `calling` to the `frameworks` array in your Karma configuration:
```javascript
module.exports = function(config){
config.set({
// ...
frameworks: ['mocha', 'calling'],
// ...
```
---
If you are not using Karma, you can still use `calling` with import or require:
```javascript
import calling from 'karma-calling';
```
```javascript
var calling = require('karma-calling');
```
Or just by inserting the script in your page:
```javascript
```
## Usage
Instead of wrapping your functions in an anonymous function, use a more natural BDD-style chaining:
### Expect
```javascript
// Instead of
expect(function () { myFunction.apply(myObject, [param1, param2]); }).to.throw(Error);
// You can use
expect(calling(myFunction).on(myObject).with(param1, param2)).to.throw(Error);
```
### Should
```javascript
// Instead of
function () { myFunction.apply(myObject, [param1, param2]); }.should.throw(Error);
// You can use
calling(myFunction).on(myObject).with(param1, param2).should.throw(Error);
```
> You can swap the order of `on` and `with` according to your preference.
## API
### calling(function)
The function/method to call.
### .on(context)
Optional binding context.
### .with(param1, ..., paramN)
Optional parameters.
## License
MIT License