☕️ Classic, reliable, trusted test framework for Node.js and the browser
Force sibling describes to have separate contexts
Jonathan Park6c705cd4d4bd
diff --git a/lib/suite.js b/lib/suite.jsindex d403a83f..b06645b5 100644--- a/lib/suite.js+++ b/lib/suite.js@@ -46,9 +46,11 @@ exports.create = function(parent, title){* @api private*/-function Suite(title, ctx) {+function Suite(title, parentContext) {this.title = title;- this.ctx = ctx;+ var context = function() {};+ context.prototype = parentContext;+ this.ctx = new context();this.suites = [];this.tests = [];this.pending = false;diff --git a/mocha.js b/mocha.jsindex 9c85199f..19edc87d 100644--- a/mocha.js+++ b/mocha.js@@ -5065,9 +5065,11 @@ exports.create = function(parent, title){* @api private*/-function Suite(title, ctx) {+function Suite(title, parentContext) {this.title = title;- this.ctx = ctx;+ var context = function () {};+ context.prototype = parentContext;+ this.ctx = new context();this.suites = [];this.tests = [];this.pending = false;diff --git a/test/acceptance/context.js b/test/acceptance/context.jsindex e2af9d5e..0d39f141 100644--- a/test/acceptance/context.js+++ b/test/acceptance/context.js@@ -23,4 +23,45 @@ describe('Context', function(){after(function(){this.calls.should.eql(['before', 'before two', 'test', 'after two']);})-})\ No newline at end of file+})++describe('Context Siblings', function(){+ beforeEach(function(){+ this.calls = ['before'];+ })++ describe('sequestered sibling', function(){+ beforeEach(function(){+ this.calls.push('before two');+ this.hiddenFromSibling = 'This should be hidden';+ })++ it('should work', function(){+ this.hiddenFromSibling.should.eql('This should be hidden')+ })+ })++ describe('sibling verifiction', function(){+ beforeEach(function(){+ this.calls.push('before sibling');+ })++ it('should not have value set within a sibling describe', function(){+ 'This should be hidden'.should.not.eql(this.hiddenFromSibling);+ this.visibleFromTestSibling = 'Visible from test sibling';+ })++ it('should allow test siblings to modify shared context', function(){+ 'Visible from test sibling'.should.eql(this.visibleFromTestSibling);+ })++ it('should have reset this.calls before describe', function(){+ this.calls.should.eql(['before', 'before sibling']);+ })+ })++ after(function(){+ this.calls.should.eql(['before', 'before sibling']);+ })++})