QUnit plugin for dependency injection into unit tests
JavaScript
Latest commit ed23952 Dec 31, 2014 @bahmutov next-updater has upgraded 9 dependencies
Hi!

I have upgraded dependencies to the latest non-breaking versions

    browserify 3.44.2 -> 3.46.1
    grunt-browserify 2.0.8 -> 2.1.4
    grunt-bump 0.0.14 -> 0.0.16
    grunt-contrib-qunit 0.5.1 -> 0.5.2
    grunt-deps-ok 0.2.0 -> 0.5.2
    grunt-nice-package 0.5.2 -> 0.9.2
    gt 0.8.38 -> 0.8.47
    pre-git 0.0.16 -> 0.1.1
    time-grunt 0.3.2 -> 0.4.0

Truly yours, [next-updater](https://github.com/bahmutov/next-updater)
Permalink
Failed to load latest commit information.
configs adding browserify Apr 25, 2014
test passing expected number of assertions, fixes #6 Jul 2, 2014
.gitignore
.jshintrc initial Apr 23, 2014
.travis.yml initial Apr 23, 2014
Gruntfile.js
LICENSE initial Apr 23, 2014
README.md added link to qunit-helpful Jul 2, 2014
bower.json bower Jul 2, 2014
index.html generating browser bundle, fixes #1 Apr 25, 2014
package.json
qunit-inject-browser.js next-updater has upgraded 9 dependencies Dec 30, 2014
qunit-inject.js

README.md

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