1.0.1 • Published 7 years ago

karma-calling v1.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

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:

$ npm install karma-calling --save-dev

2. Add calling to the frameworks array in your Karma configuration:

module.exports = function(config){
  config.set({
    // ...
    frameworks: ['mocha', 'calling'],
    // ...

If you are not using Karma, you can still use calling with import or require:

import calling from 'karma-calling';
var calling = require('karma-calling');

Or just by inserting the script in your page:

<script src='karma-calling.js'></script>

Usage

Instead of wrapping your functions in an anonymous function, use a more natural BDD-style chaining:

Expect

  // 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

  // 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