Skip to content

Commit

Permalink
Core: Module shared environments
Browse files Browse the repository at this point in the history
  • Loading branch information
leobalter committed Oct 1, 2015
1 parent 78ecd87 commit 29f5b84
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core.js
Expand Up @@ -41,7 +41,7 @@ extend( QUnit, {
if ( executeNow instanceof Function ) {
config.moduleStack.push( module );
setCurrentModule( module );
executeNow( moduleFns );
executeNow.call( module.testEnvironment, moduleFns );
config.moduleStack.pop();
module = module.parentModule || currentModule;
}
Expand Down
22 changes: 22 additions & 0 deletions test/main/modules.js
Expand Up @@ -242,3 +242,25 @@ QUnit.module( "contained suite arguments", function( hooks ) {
} );
} );
} );

QUnit.module( "contained suite `this`", function( hooks ) {
this.outerBefore = 0;

hooks.beforeEach( function() {
this.outerBefore++;
} );

hooks.afterEach( function( assert ) {
assert.equal( this.outerBefore, 42 );
} );

QUnit.test( "`this` is shared from modules to the tests", function( assert ) {
assert.equal(this.outerBefore, 1, "beforeEach updated environment" );
this.outerBefore += 41;
} );

QUnit.test( "sibling tests don't share environments", function( assert ) {
assert.equal(this.outerBefore, 1 );
this.outerBefore += 41;
} );
} );

0 comments on commit 29f5b84

Please sign in to comment.