qunit-inject

0.5.0 • Public • Published

qunit-inject

QUnit plugin to add dependency injection from module to unit tests.

Test page

NPM

Build status dependencies devdependencies

endorse

Example:

QUnit.module('inject two variable', {
  a: 10,
  b: 32
});
 
QUnit.test('injected values', function (a, b) {
  QUnit.equal(a, 10, 'valua a injected');
  QUnit.equal(b, 32, 'valua b injected');
});

You can create / modify values to be injected in setup function

QUnit.module('inject with setup', {
  a: 10,
  setup: function () {
    this.a = 42;
  }
});
// a = 42 in each unit test that needs it

Install

Node:

npm install qunit-inject --save-dev
// load qunit-inject before unit tests

Browser:

bower install qunit-inject
// include the qunit js script first, then
<script src="bower_components/qunit-inject/qunit-inject-browser.js"></script>
// then include user tests

Partial injection

qunit-inject correctly handles assert argument in each test using partial injection.

QUnit.module('QUnit.assert tests WITH injection', {
  a: 42,
  b: 1
});
QUnit.test('injection sandwich', function (b, assert, a) {
  assert.equal(a, 42, 'assert works');
  assert.equal(b, 1, 'b value');
});

Related

Dependency injection implemented using heroin

Other QUnit plugins I made:

Limitation

The injection is not minification safe, since minifier shortens the argument names.

Small print

Author: Gleb Bahmutov © 2014 @bahmutov

License: MIT - do anything with the code, but don't blame me if it does not work.

Support: if you find any problems with this module, email / tweet / open issue on Github

Readme

Keywords

Package Sidebar

Install

npm i qunit-inject

Weekly Downloads

0

Version

0.5.0

License

MIT

Last publish

Collaborators

  • bahmutov