Skip to content

Commit

Permalink
Core: Remove the newly introduced global hooks until we have consensus
Browse files Browse the repository at this point in the history
Between locating the hooks in `QUnit` or `QUnit.config` and making them
simple setters and callback lists (like QUnit.done et al) and upcoming
plans for nested suites, we decided not to release this feature, for now.

I'm keeping the abstractions for hooks in place, so it should be trivial
to bring this back in whatever form we decide on later.

Effectively reverts 5ee31a0 and follow-up
commits.

Fixes qunitjs#665
Ref qunitjs#633
Ref qunitjs#635
Ref qunitjs#647
  • Loading branch information
jzaefferer committed Oct 10, 2014
1 parent 99f10ea commit e6262d9
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 62 deletions.
4 changes: 1 addition & 3 deletions src/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ Test.prototype = {
};
},

// Currently only used for module-level hooks, can be used to add global level ones
hooks: function( handler ) {
var hooks = [];

Expand All @@ -133,9 +134,6 @@ Test.prototype = {
return hooks;
}

if ( QUnit.objectType( config[ handler ] ) === "function" ) {
hooks.push( this.queueHook( config[ handler ], handler ) );
}
if ( this.moduleTestEnvironment && QUnit.objectType( this.moduleTestEnvironment[ handler ] ) === "function" ) {
hooks.push( this.queueHook( this.moduleTestEnvironment[ handler ], handler ) );
}
Expand Down
59 changes: 0 additions & 59 deletions test/modules.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,3 @@
// Before and after each tests
QUnit.config.beforeEach = function() {
this.lastHook = "global-beforeEach";
};

QUnit.config.afterEach = function( assert ) {
if ( this.hooksTest ) {
assert.strictEqual( this.lastHook, "module-afterEach", "Global afterEach runs after module's afterEach" );
this.hooksTest = false;
}

if ( this.contextTest ) {
assert.ok( true );
this.contextTest = false;
}
};

QUnit.module( "beforeEach/afterEach", {
beforeEach: function( assert ) {
assert.strictEqual( this.lastHook, "global-beforeEach", "Global beforeEach runs before module's beforeEach" );
this.lastHook = "module-beforeEach";
},
afterEach: function( assert ) {
if ( this.hooksTest ) {
assert.strictEqual( this.lastHook, "test-block", "Module's afterEach runs after current test block" );
this.lastHook = "module-afterEach";
}
}
});

QUnit.test( "hooks order", function( assert ) {
assert.expect( 4 );

// This will trigger an assertion on the global and one on the module's afterEach
this.hooksTest = true;

assert.strictEqual( this.lastHook, "module-beforeEach", "Module's beforeEach runs before current test block" );
this.lastHook = "test-block";
});

QUnit.module( "Test context object", {
beforeEach: function( assert ) {
var key,
keys = [];

for ( key in this ) {
keys.push( key );
}
assert.deepEqual( keys, [ "helper", "lastHook" ] );
},
afterEach: function() {},
helper: function() {}
});

QUnit.test( "keys", function( assert ) {
assert.expect( 2 );
this.contextTest = true;
});

QUnit.module( "afterEach and QUnit.stop", {
beforeEach: function() {
this.state = false;
Expand Down

0 comments on commit e6262d9

Please sign in to comment.