Skip to content

Commit

Permalink
Apply notrycatch option to setup and teardown as well. Fixes qunitjs#203
Browse files Browse the repository at this point in the history
. Reorder noglobals check to allow teardown to remove globals that were introduced intentionally. Fixes qunitjs#204
  • Loading branch information
jzaefferer committed Mar 5, 2012
1 parent 607bc4c commit 948894a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
24 changes: 16 additions & 8 deletions qunit/qunit.js
Expand Up @@ -85,11 +85,14 @@ Test.prototype = {
// TODO why??
QUnit.current_testEnvironment = this.testEnvironment;

if ( !config.pollution ) {
saveGlobal();
}
if ( config.notrycatch ) {
this.testEnvironment.setup.call(this.testEnvironment);
return;
}
try {
if ( !config.pollution ) {
saveGlobal();
}

this.testEnvironment.setup.call(this.testEnvironment);
} catch(e) {
QUnit.ok( false, "Setup failed on " + this.testName + ": " + e.message );
Expand Down Expand Up @@ -121,12 +124,17 @@ Test.prototype = {
},
teardown: function() {
config.current = this;
try {
if ( config.notrycatch ) {
this.testEnvironment.teardown.call(this.testEnvironment);
checkPollution();
} catch(e) {
QUnit.ok( false, "Teardown failed on " + this.testName + ": " + e.message );
return;
} else {
try {
this.testEnvironment.teardown.call(this.testEnvironment);
} catch(e) {
QUnit.ok( false, "Teardown failed on " + this.testName + ": " + e.message );
}
}
checkPollution();
},
finish: function() {
config.current = this;
Expand Down
4 changes: 4 additions & 0 deletions test/test.js
Expand Up @@ -34,9 +34,13 @@ module("setup/teardown test", {
setup: function() {
state = true;
ok(true);
x = 1;
},
teardown: function() {
ok(true);
// can introduce and delete globals in setup/teardown
// without noglobals sounding the alarm
delete x;
}
});

Expand Down

0 comments on commit 948894a

Please sign in to comment.