Merge branch 'bonkevin-spec-suite-properties-accessors'

* Merges #2072 from @bonkevin
* Adds Env#getSpecProperty
This commit is contained in:
Steve Gravrock
2025-08-30 07:58:36 -07:00
6 changed files with 139 additions and 2 deletions

View File

@@ -779,6 +779,26 @@ getJasmineRequireObj().Env = function(j$) {
return suiteBuilder.fit(description, fn, timeout, filename).metadata;
};
/**
* Get a user-defined property as part of the properties field of {@link SpecResult}
* @name Env#getSpecProperty
* @since 5.10.0
* @function
* @param {String} key The name of the property
* @returns {*} The value of the property
*/
this.getSpecProperty = function(key) {
if (
!runner.currentRunable() ||
runner.currentRunable() == runner.currentSuite()
) {
throw new Error(
"'getSpecProperty' was used when there was no current spec"
);
}
return runner.currentRunable().getSpecProperty(key);
};
/**
* Sets a user-defined property that will be provided to reporters as part of the properties field of {@link SpecResult}
* @name Env#setSpecProperty

View File

@@ -63,6 +63,11 @@ getJasmineRequireObj().Spec = function(j$) {
}
};
Spec.prototype.getSpecProperty = function(key) {
this.result.properties = this.result.properties || {};
return this.result.properties[key];
};
Spec.prototype.setSpecProperty = function(key, value) {
this.result.properties = this.result.properties || {};
this.result.properties[key] = value;

View File

@@ -168,6 +168,18 @@ getJasmineRequireObj().interface = function(jasmine, env) {
return env.afterAll.apply(env, arguments);
},
/**
* Get a user-defined property as part of the properties field of {@link SpecResult}
* @name getSpecProperty
* @since 5.10.0
* @function
* @param {String} key The name of the property
* @returns {*} The value of the property
*/
getSpecProperty: function(key) {
return env.getSpecProperty(key);
},
/**
* Sets a user-defined property that will be provided to reporters as part of the properties field of {@link SpecResult}
* @name setSpecProperty