Adds one time module setup and teardown support to QUnit
JavaScript CSS
Latest commit 0856a6d Dec 30, 2014 @bahmutov next-updater has upgraded 10 dependencies
Hi!

I have upgraded dependencies to the latest non-breaking versions

    grunt 0.4.4 -> 0.4.5
    grunt-bump 0.0.13 -> 0.0.16
    grunt-complexity 0.1.51 -> 0.2.0
    grunt-contrib-qunit 0.4.0 -> 0.5.2
    grunt-deps-ok 0.1.8 -> 0.5.2
    grunt-nice-package 0.4.0 -> 0.9.2
    grunt-npm2bower-sync 0.3.0 -> 0.4.0
    gt 0.8.36 -> 0.8.47
    pre-git 0.0.15 -> 0.1.1
    time-grunt 0.3.1 -> 0.4.0

Truly yours, [next-updater](https://github.com/bahmutov/next-updater)

README.md

qunit-once

QUnit plugin that adds setupOne and teardownOnce to modules

Test page

NPM

Build status dependencies devdependencies

endorse

Available through bower and npm as qunit-once.

Tested in the browser by QUnit and under nodejs by qunit-node. Safe to use with gt, which includes setupOnce and teardownOnce already.

API

QUnit.module('Example', {
  setupOnce: function () {
    // runs once before anything else in the module
  },
  setup: function () {
    // runs before each unit test
  },
  teardown: function () {
    // runs after EACH unit test in this module
  },
  teardownOnce: function () {
    // runs once after all unit tests finished (including teardown)
  }
});

Use

install

Include qunit-once.js after qunit.js in HTML

<script src="http://code.jquery.com/qunit/qunit-1.12.0.js"></script>
<script src="qunit-once.js"></script>
<script src="tests.js"></script>

Or install qunit-once via npm install qunit-once --save-dev under node.

Write unit tests

  // tests.js
  var counter = 0;

  QUnit.module('Example', {
    setupOnce: function () {
      counter = 1;
    },
    setup: function () {
      counter += 1;
    }
  });

  QUnit.test('first', function () {
    QUnit.equal(counter, 2, 'setupOnce followed by setup');
    counter = 0;
  });

  QUnit.test('second', function () {
    QUnit.equal(counter, 1, 'first test followed by setup');
  });

Run under node using node-qunit or gt

npm install -g qunit
qunit -d qunit-once.js -c tests.js -t tests.js

You don't need to include this module when running with gt, it already supports setupOnce and teardownOnce methods.

Related

Run QUnit module setup once, Testing code with async setup, qunit-promises

Small print

Author: Gleb Bahmutov © 2013 @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