Require spec/suite property keys to be strings, not just anything that's cloneable and serializable
This matches the jsdoc.
This commit is contained in:
@@ -849,8 +849,11 @@ getJasmineRequireObj().Spec = function(j$) {
|
||||
// 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$.private.util.assertReporterCloneable(key, 'Key');
|
||||
if (!j$.private.isString(key)) {
|
||||
throw new Error('Key must be a string');
|
||||
}
|
||||
j$.private.util.assertReporterCloneable(value, 'Value');
|
||||
|
||||
this.#executionState.properties = this.#executionState.properties || {};
|
||||
this.#executionState.properties[key] = value;
|
||||
}
|
||||
@@ -10851,8 +10854,11 @@ getJasmineRequireObj().Suite = function(j$) {
|
||||
// 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$.private.util.assertReporterCloneable(key, 'Key');
|
||||
if (!j$.private.isString(key)) {
|
||||
throw new Error('Key must be a string');
|
||||
}
|
||||
j$.private.util.assertReporterCloneable(value, 'Value');
|
||||
|
||||
this.#result.properties = this.#result.properties || {};
|
||||
this.#result.properties[key] = value;
|
||||
}
|
||||
|
||||
@@ -103,26 +103,14 @@ describe('Spec', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('throws if the key is not structured-cloneable', function() {
|
||||
it('throws if the key is not a string', function() {
|
||||
const spec = new privateUnderTest.Spec({
|
||||
queueableFn: { fn: () => {} }
|
||||
});
|
||||
|
||||
expect(function() {
|
||||
spec.setSpecProperty(new Promise(() => {}), '');
|
||||
}).toThrowError("Key can't be cloned");
|
||||
});
|
||||
|
||||
it('throws if the key is not JSON-serializable', function() {
|
||||
const spec = new privateUnderTest.Spec({
|
||||
queueableFn: { fn: () => {} }
|
||||
});
|
||||
|
||||
expect(function() {
|
||||
const k = {};
|
||||
k.self = k;
|
||||
spec.setSpecProperty(k, '');
|
||||
}).toThrowError("Key can't be cloned");
|
||||
spec.setSpecProperty({}, '');
|
||||
}).toThrowError('Key must be a string');
|
||||
});
|
||||
|
||||
it('throws if the value is not structured-cloneable', function() {
|
||||
|
||||
@@ -409,12 +409,12 @@ describe('Suite', function() {
|
||||
});
|
||||
|
||||
describe('#setSuiteProperty', function() {
|
||||
it('throws if the key is not structured-cloneable', function() {
|
||||
it('throws if the key is not a string', function() {
|
||||
const suite = new privateUnderTest.Suite({});
|
||||
|
||||
expect(function() {
|
||||
suite.setSuiteProperty(new Promise(() => {}), '');
|
||||
}).toThrowError("Key can't be cloned");
|
||||
suite.setSuiteProperty({}, '');
|
||||
}).toThrowError('Key must be a string');
|
||||
});
|
||||
|
||||
it('throws if the value is not structured-cloneable', function() {
|
||||
@@ -424,6 +424,16 @@ describe('Suite', function() {
|
||||
suite.setSuiteProperty('k', new Promise(() => {}));
|
||||
}).toThrowError("Value can't be cloned");
|
||||
});
|
||||
|
||||
it('throws if the value is not JSON-serializable', function() {
|
||||
const suite = new privateUnderTest.Suite({});
|
||||
|
||||
expect(function() {
|
||||
const v = {};
|
||||
v.self = v;
|
||||
suite.setSuiteProperty('k', v);
|
||||
}).toThrowError("Value can't be cloned");
|
||||
});
|
||||
});
|
||||
|
||||
describe('#startedEvent', function() {
|
||||
|
||||
@@ -72,8 +72,11 @@ getJasmineRequireObj().Spec = function(j$) {
|
||||
// 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$.private.util.assertReporterCloneable(key, 'Key');
|
||||
if (!j$.private.isString(key)) {
|
||||
throw new Error('Key must be a string');
|
||||
}
|
||||
j$.private.util.assertReporterCloneable(value, 'Value');
|
||||
|
||||
this.#executionState.properties = this.#executionState.properties || {};
|
||||
this.#executionState.properties[key] = value;
|
||||
}
|
||||
|
||||
@@ -37,8 +37,11 @@ getJasmineRequireObj().Suite = function(j$) {
|
||||
// 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$.private.util.assertReporterCloneable(key, 'Key');
|
||||
if (!j$.private.isString(key)) {
|
||||
throw new Error('Key must be a string');
|
||||
}
|
||||
j$.private.util.assertReporterCloneable(value, 'Value');
|
||||
|
||||
this.#result.properties = this.#result.properties || {};
|
||||
this.#result.properties[key] = value;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user