Validate that setSuiteProperty and setSpecProperty args are cloneable
This commit is contained in:
@@ -70,8 +70,12 @@ getJasmineRequireObj().Spec = function(j$) {
|
||||
return this.result.properties[key];
|
||||
}
|
||||
|
||||
// TODO: throw if the key or value is not structred cloneable
|
||||
setSpecProperty(key, value) {
|
||||
// Key and value will eventually be cloned during reporting. The error
|
||||
// thrown at that point if they aren't cloneable isn't very helpful.
|
||||
// Throw a better one now.
|
||||
j$.util.assertStructuredCloneable(key, 'Key');
|
||||
j$.util.assertStructuredCloneable(value, 'Value');
|
||||
this.result.properties = this.result.properties || {};
|
||||
this.result.properties[key] = value;
|
||||
}
|
||||
|
||||
@@ -31,6 +31,11 @@ getJasmineRequireObj().Suite = function(j$) {
|
||||
}
|
||||
|
||||
setSuiteProperty(key, value) {
|
||||
// Key and value will eventually be cloned during reporting. The error
|
||||
// thrown at that point if they aren't cloneable isn't very helpful.
|
||||
// Throw a better one now.
|
||||
j$.util.assertStructuredCloneable(key, 'Key');
|
||||
j$.util.assertStructuredCloneable(value, 'Value');
|
||||
this.result.properties = this.result.properties || {};
|
||||
this.result.properties[key] = value;
|
||||
}
|
||||
|
||||
@@ -80,5 +80,13 @@ getJasmineRequireObj().util = function(j$) {
|
||||
}
|
||||
};
|
||||
|
||||
util.assertStructuredCloneable = function(v, msgPrefix) {
|
||||
try {
|
||||
structuredClone(v);
|
||||
} catch (e) {
|
||||
throw new Error(`${msgPrefix} can't be cloned`, { cause: e });
|
||||
}
|
||||
};
|
||||
|
||||
return util;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user