Skip to content

Commit

Permalink
Make test fail if no assertions run. Fixes qunitjs#178
Browse files Browse the repository at this point in the history
  • Loading branch information
jzaefferer committed Mar 5, 2012
1 parent 3c653d4 commit 5d26d23
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions qunit/qunit.js
Expand Up @@ -132,6 +132,8 @@ Test.prototype = {
config.current = this;
if ( this.expected != null && this.expected != this.assertions.length ) {
QUnit.ok( false, "Expected " + this.expected + " assertions, but " + this.assertions.length + " were run" );
} else if ( this.expected == null && !this.assertions.length ) {
QUnit.ok( false, "Expected at least one assertion, but none were run - call expect(0) to accept zero assertions." );
}

var good = 0, bad = 0,
Expand Down
5 changes: 5 additions & 0 deletions test/test.js
Expand Up @@ -193,6 +193,7 @@ test("scope check", function() {
deepEqual(this.foo, "bar");
});
test("modify testEnvironment",function() {
expect(0);
this.foo="hamster";
});
test("testEnvironment reset for next test",function() {
Expand All @@ -209,6 +210,7 @@ test("scope check", function() {
deepEqual(this.options, {recipe:"soup",ingredients:["hamster","onions"]}) ;
});
test("modify testEnvironment",function() {
expect(0);
// since we do a shallow copy, the testEnvironment can be modified
this.options.ingredients.push("carrots");
});
Expand Down Expand Up @@ -306,6 +308,7 @@ if (typeof document !== "undefined") {

module("fixture");
test("setup", function() {
expect(0);
document.getElementById("qunit-fixture").innerHTML = "foobar";
});
test("basics", function() {
Expand Down Expand Up @@ -445,12 +448,14 @@ test('Circular reference - test reported by soniciq in #105', function() {
}
module("reset");
test("reset runs assertions", function() {
expect(0);
QUnit.reset = function() {
afterTest();
reset.apply( this, arguments );
};
});
test("reset runs assertions2", function() {
expect(0);
QUnit.reset = reset;
});
})();
Expand Down

0 comments on commit 5d26d23

Please sign in to comment.