From 27a1257b6d29f1a981b49ac81feef5fffc6cd27f Mon Sep 17 00:00:00 2001 From: bonkevin Date: Wed, 29 Oct 2025 13:04:10 -0400 Subject: [PATCH] fix: unavailable custom matchers on top-`it` --- spec/core/integration/EnvSpec.js | 28 ++++++++++++++++++++++++++++ src/core/TreeRunner.js | 5 ++++- 2 files changed, 32 insertions(+), 1 deletion(-) 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) => {