0.5.0 • Published 10 years ago

qunit-inject v0.5.0

Weekly downloads
69
License
MIT
Repository
github
Last release
10 years ago

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

0.5.0

10 years ago

0.4.0

10 years ago

0.3.0

10 years ago

0.2.1

10 years ago

0.2.0

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago