Navigation Menu

Skip to content

Commit

Permalink
Core: Share on module contained suites
Browse files Browse the repository at this point in the history
  • Loading branch information
leobalter committed Oct 1, 2015
1 parent 29f5b84 commit 53778e3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
11 changes: 10 additions & 1 deletion src/core.js
Expand Up @@ -56,9 +56,18 @@ extend( QUnit, {
var module = {
name: moduleName,
parentModule: parentModule,
testEnvironment: testEnvironment,
tests: []
};

var env = {};
if ( parentModule ) {
extend( env, parentModule.testEnvironment );
delete env.beforeEach;
delete env.afterEach;
}
extend( env, testEnvironment );
module.testEnvironment = env;

config.modules.push( module );
return module;
}
Expand Down
35 changes: 28 additions & 7 deletions test/main/modules.js
Expand Up @@ -244,23 +244,44 @@ QUnit.module( "contained suite arguments", function( hooks ) {
} );

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

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

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

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

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

QUnit.module( "nested suite `this`", function( hooks ) {
this.inner = true;

hooks.beforeEach( function( assert ) {
assert.ok( this.outer );
assert.ok( this.inner );
} );

hooks.afterEach( function( assert ) {
assert.ok( this.outer );
assert.ok( this.inner );
} );

QUnit.test( "inner modules share outer environments", function( assert ) {
assert.ok( this.outer );
assert.ok( this.inner );
} );
} );

QUnit.test( "tests can't see environments from nested modules", function( assert ) {
assert.strictEqual( this.inner, undefined );
} );
} );

0 comments on commit 53778e3

Please sign in to comment.