Skip to content

Commit

Permalink
Core: Allow hooks via this.hooks in nested modules.
Browse files Browse the repository at this point in the history
  • Loading branch information
rwjblue committed Jun 15, 2017
1 parent bbae0a9 commit 10aa04b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/core.js
Expand Up @@ -93,7 +93,9 @@ function processModule( name, options, executeNow ) {
if ( objectType( executeNow ) === "function" ) {
moduleStack.push( module );
config.currentModule = module;
executeNow.call( module.testEnvironment, moduleFns );
testEnvironment.hooks = moduleFns;
executeNow.call( testEnvironment, moduleFns );
delete testEnvironment.hooks;
moduleStack.pop();
module = module.parentModule || currentModule;
}
Expand Down
26 changes: 26 additions & 0 deletions test/main/modules.js
Expand Up @@ -419,3 +419,29 @@ QUnit.module( "modules with multiple hooks", function( hooks ) {
assert.expect( 9 );
} );
} );

QUnit.module( "modules with hooks added via `this.hooks.*`", function( hooks ) {
var hooksMatchesThisHooks = hooks === this.hooks;

this.hooks.before( function( assert ) { assert.step( "before1" ); } );
this.hooks.beforeEach( function( assert ) { assert.step( "beforeEach1" ); } );
this.hooks.afterEach( function( assert ) { assert.step( "afterEach1" ); } );

this.hooks.after( function( assert ) {
assert.ok( hooksMatchesThisHooks, "`this.hooks` matches `hooks` argument" );
assert.step( "after1" );

assert.verifySteps( [
"before1",
"beforeEach1",
"afterEach1",
"after1"
] );

} );

QUnit.test( "all hooks", function( assert ) {
assert.expect( 7 );
assert.equal( this.hooks, undefined );
} );
} );

0 comments on commit 10aa04b

Please sign in to comment.