Permalink
Browse files

Use submodule instead of hardcoded copy of QUnit.

* While at it, updating QUnit to 1.9.0+. Fixes #52.
  $ cd support/qunit
  $ git checkout v1.9.0 # this is a tag in jquery/qunit
  $ cd ../..
  $ git add support/qunit # stages the change to the submodule pointer
  $ git commit ..

* Updating read me document to reflect the latest standard.
  Old format is still completely compatible, but should not be
  encouraged.
  Also:
  - equals() -> equal()
  - same() -> deepEqual()
  - raises() -> throws()

  Follows-up: 4252119

* Tests are passing (`npm test`)
  • Loading branch information...
1 parent 8ffe8b4 commit 673f9d6b1339623b2f20a2b8e75f8db03a04d2b7 @Krinkle Krinkle committed Jul 16, 2012
Showing with 51 additions and 1,916 deletions.
  1. +1 −1 .gitignore
  2. +3 −0 .gitmodules
  3. +1 −1 lib/child.js
  4. +45 −50 readme.md
  5. +1 −0 support/qunit
  6. +0 −1,864 support/qunit/qunit.js
View
@@ -1,2 +1,2 @@
.DS_Store
-node_modules
+node_modules
View
@@ -0,0 +1,3 @@
+[submodule "support/qunit"]
+ path = support/qunit
+ url = https://github.com/jquery/qunit.git
View
@@ -1,4 +1,4 @@
-var QUnit = require('../support/qunit/qunit'),
+var QUnit = require('../support/qunit/qunit/qunit.js'),
path = require('path'),
_ = require('underscore'),
trace = require('tracejs').trace;
View
@@ -26,48 +26,48 @@ http://docs.jquery.com/QUnit
#### Setup
// Add a test to run.
- test(name, expected, test)
+ QUnit.test(name, expected, test)
// Add an asynchronous test to run. The test must include a call to start().
- asyncTest(name, expected, test)
+ QUnit.asyncTest(name, expected, test)
// Specify how many assertions are expected to run within a test.
- expect(amount);
+ QUnit.expect(amount);
// Separate tests into modules.
- module(name, lifecycle)
+ QUnit.module(name, lifecycle)
#### Assertions
// A boolean assertion, equivalent to JUnit's assertTrue. Passes if the first argument is truthy.
- ok(state, message)
+ assert.ok(state, message)
// A comparison assertion, equivalent to JUnit's assertEquals. Uses "==".
- equal(actual, expected, message)
+ assert.equal(actual, expected, message)
- // A comparison assertion, equivalent to JUnit's assertEquals. Uses "==".
- notEqual(actual, expected, message)
+ // A comparison assertion, equivalent to JUnit's assertEquals. Uses "!=".
+ assert.notEqual(actual, expected, message)
// A deep recursive comparison assertion, working on primitive types, arrays and objects.
- deepEqual(actual, expected, message)
+ assert.deepEqual(actual, expected, message)
// A deep recursive comparison assertion, working on primitive types, arrays and objects, with the result inverted, passing // when some property isn't equal.
- notDeepEqual(actual, expected, message)
+ assert.notDeepEqual(actual, expected, message)
// A comparison assertion. Uses "===".
- strictEqual(actual, expected, message)
+ assert.strictEqual(actual, expected, message)
- // A stricter comparison assertion then notEqual. Uses "===".
- notStrictEqual(actual, expected, message)
+ // A stricter comparison assertion then notEqual. Uses "!==".
+ assert.notStrictEqual(actual, expected, message)
// Assertion to test if a callback throws an exception when run.
- raises(actual, message)
+ assert.throws(actual, message)
#### Asynchronous Testing
// Start running tests again after the testrunner was stopped.
- start()
+ QUnit.start()
// Stop the testrunner to wait to async tests to run. Call start() to continue.
- stop(timeout)
+ QUnit.stop(timeout)
### Usage
@@ -206,68 +206,63 @@ variable name to be used for the namespace object, followed by a colon:
QUnit API and code which have to be tested are already loaded and attached to the global context.
-Because nodejs modules reserved "module" namespace we have to redefine it from QUnit namespace.
-
- module = QUnit.module;
-
-Basically QUnit API can ba accessed directly from global object or optional via "QUnit" object.
-
- QUnit.test;
-
Some tests examples
- test("a basic test example", function() {
- ok(true, "this test is fine");
+
+ QUnit.test("a basic test example", function (assert) {
+ assert.ok(true, "this test is fine");
var value = "hello";
- equals("hello", value, "We expect value to be hello");
+ assert.equal("hello", value, "We expect value to be hello");
});
- module("Module A");
+ QUnit.module("Module A");
- test("first test within module", 1, function() {
- ok(true, "all pass");
+ QUnit.test("first test within module", 1, function (assert) {
+ assert.ok(true, "a dummy");
});
- test("second test within module", 2, function() {
- ok(true, "all pass");
+ QUnit.test("second test within module", 2, function (assert) {
+ assert.ok(true, "dummy 1 of 2");
+ assert.ok(true, "dummy 2 of 2");
});
- module("Module B", {
- setup: function() {
+ QUnit.module("Module B", {
+ setup: function () {
// do some initial stuff before every test for this module
},
- teardown: function() {
+ teardown: function () {
// do some stuff after every test for this module
}
});
- test("some other test", function() {
- expect(2);
- equals(true, false, "failing test");
- equals(true, true, "passing test");
+ QUnit.test("some other test", function (assert) {
+ QUnit.expect(2);
+ assert.equal(true, false, "failing test");
+ assert.equal(true, true, "passing test");
});
- module("Module C", {
+ QUnit.module("Module C", {
setup: function() {
// setup a shared environment for each test
- this.options = {test: 123};
+ this.options = { test: 123 };
}
});
- test("this test is using shared environment", 1, function() {
- same({test:123}, this.options, "passing test");
+ QUnit.test("this test is using shared environment", 1, function (assert) {
+ assert.deepEqual({ test: 123 }, this.options, "passing test");
});
- test("this is an async test example", function() {
- expect(2);
- stop();
- setTimeout(function() {
- ok(true, "finished async test");
- strictEqual(true, true, "Strict equal assertion uses ===");
- start();
+ QUnit.test("this is an async test example", function (assert) {
+ QUnit.expect(2);
+ QUnit.stop();
+ setTimeout(function () {
+ assert.ok(true, "finished async test");
+ assert.strictEqual(true, true, "Strict equal assertion uses ===");
+ QUnit.start();
}, 100);
});
+
### Run tests
npm i
Submodule qunit added at e98069
Oops, something went wrong.

0 comments on commit 673f9d6

Please sign in to comment.