diff --git a/src/core.js b/src/core.js index 7680b1904..e28ceb325 100644 --- a/src/core.js +++ b/src/core.js @@ -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; } diff --git a/test/main/modules.js b/test/main/modules.js index 21a3f7efe..6519b80cb 100644 --- a/test/main/modules.js +++ b/test/main/modules.js @@ -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 ); + } ); +} );