diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index efb80d5f..fdc74dc5 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -11514,7 +11514,10 @@ getJasmineRequireObj().TreeRunner = function(j$) { _executeSpec(spec, specOverallDone) { const onStart = next => { this.#currentRunableTracker.setCurrentSpec(spec); - this.#runableResources.initForRunable(spec.id, spec.parentSuiteId); + this.#runableResources.initForRunable( + spec.id, + spec.parentSuiteId || this.#executionTree.topSuite.id + ); this.#reportDispatcher.specStarted(spec.result).then(next); }; const resultCallback = (result, next) => { diff --git a/spec/core/integration/EnvSpec.js b/spec/core/integration/EnvSpec.js index d9224d40..b6bdbadf 100644 --- a/spec/core/integration/EnvSpec.js +++ b/spec/core/integration/EnvSpec.js @@ -2277,6 +2277,34 @@ describe('Env integration', function() { await env.execute(); }); + it('Custom matchers set in top-level beforeAll should be available to all specs and suites', async function() { + const matchers = { + toFoo: function() {} + }; + + env.beforeAll(function() { + env.addMatchers(matchers); + }); + + env.describe('suite - top-level', function() { + env.it('has access to the custom matcher', function() { + expect(env.expect().toFoo).toBeDefined(); + }); + + env.describe('suite - nested', function() { + env.it('has access to the custom matcher', function() { + expect(env.expect().toFoo).toBeDefined(); + }); + }); + }); + + env.it('spec - top-level - has access to the custom matcher', function() { + expect(env.expect().toFoo).toBeDefined(); + }); + + await env.execute(); + }); + it('throws an exception if you try to create a spy outside of a runnable', async function() { const obj = { fn: function() {} }; let exception; diff --git a/src/core/TreeRunner.js b/src/core/TreeRunner.js index 8b7c5703..581dc0c5 100644 --- a/src/core/TreeRunner.js +++ b/src/core/TreeRunner.js @@ -47,7 +47,10 @@ getJasmineRequireObj().TreeRunner = function(j$) { _executeSpec(spec, specOverallDone) { const onStart = next => { this.#currentRunableTracker.setCurrentSpec(spec); - this.#runableResources.initForRunable(spec.id, spec.parentSuiteId); + this.#runableResources.initForRunable( + spec.id, + spec.parentSuiteId || this.#executionTree.topSuite.id + ); this.#reportDispatcher.specStarted(spec.result).then(next); }; const resultCallback = (result, next) => {