Remove expected and actual properties of expectation results

This commit is contained in:
Steve Gravrock
2025-09-14 09:48:01 -07:00
parent 6ab83e25d1
commit 4d3f6b272a
4 changed files with 3 additions and 63 deletions

View File

@@ -2529,20 +2529,11 @@ getJasmineRequireObj().buildExpectationResult = function(j$) {
/**
* Describes the result of evaluating an expectation
*
* Note: The expected and actual properties are deprecated and may be removed
* in a future release. In many Jasmine configurations they are passed
* through JSON serialization and deserialization, which is inherently
* lossy. In such cases, the expected and actual values may be placeholders
* or approximations of the original objects. jasmine-browser-runner 3.0 and
* later omits them entirely.
*
* @typedef ExpectationResult
* @property {String} matcherName - The name of the matcher that was executed for this expectation.
* @property {String} message - The failure message for the expectation.
* @property {String} stack - The stack trace for the failure if available.
* @property {Boolean} passed - Whether the expectation passed or failed.
* @property {Object} expected - Deprecated. If the expectation failed, what was the expected value.
* @property {Object} actual - Deprecated. If the expectation failed, what actual value was produced.
* @property {String|undefined} globalErrorType - The type of an error that
* is reported on the top suite. Valid values are undefined, "afterAll",
* "load", "lateExpectation", and "lateError".
@@ -2555,21 +2546,12 @@ getJasmineRequireObj().buildExpectationResult = function(j$) {
};
if (!result.passed) {
result.expected = options.expected;
result.actual = options.actual;
if (options.error && !j$.isString_(options.error)) {
if ('code' in options.error) {
result.code = options.error.code;
}
if (
options.error.code === 'ERR_ASSERTION' &&
options.expected === '' &&
options.actual === ''
) {
result.expected = options.error.expected;
result.actual = options.error.actual;
if (options.error.code === 'ERR_ASSERTION') {
result.matcherName = 'assert ' + options.error.operator;
}
}

View File

@@ -337,8 +337,6 @@ describe('Spec', function() {
message: 'foo thrown',
matcherName: '',
passed: false,
expected: '',
actual: '',
stack: null
}
]);

View File

@@ -63,50 +63,28 @@ describe('buildExpectationResult', function() {
expect(result.matcherName).toBe('some-value');
});
it('expected returns passed expected', function() {
const result = jasmineUnderTest.buildExpectationResult({
expected: 'some-value'
});
expect(result.expected).toBe('some-value');
});
it('actual returns passed actual', function() {
const result = jasmineUnderTest.buildExpectationResult({
actual: 'some-value'
});
expect(result.actual).toBe('some-value');
});
it('handles nodejs assertions', function() {
if (typeof require === 'undefined') {
pending('This test only runs in Node');
}
const assert = require('assert');
const value = 8421;
const expectedValue = 'JasmineExpectationTestValue';
let error;
try {
assert.equal(value, expectedValue);
assert.equal('a', 'b');
} catch (e) {
error = e;
}
expect(error.code).toEqual('ERR_ASSERTION');
expect(error.actual).toEqual(value);
expect(error.expected).toEqual(expectedValue);
expect(error.operator).toEqual('==');
const result = jasmineUnderTest.buildExpectationResult({
passed: false,
matcherName: '',
expected: '',
actual: '',
error: error
});
expect(result.code).toEqual('ERR_ASSERTION');
expect(result.actual).toEqual(value);
expect(result.expected).toEqual(expectedValue);
expect(result.matcherName).toEqual('assert ==');
});
});

View File

@@ -6,20 +6,11 @@ getJasmineRequireObj().buildExpectationResult = function(j$) {
/**
* Describes the result of evaluating an expectation
*
* Note: The expected and actual properties are deprecated and may be removed
* in a future release. In many Jasmine configurations they are passed
* through JSON serialization and deserialization, which is inherently
* lossy. In such cases, the expected and actual values may be placeholders
* or approximations of the original objects. jasmine-browser-runner 3.0 and
* later omits them entirely.
*
* @typedef ExpectationResult
* @property {String} matcherName - The name of the matcher that was executed for this expectation.
* @property {String} message - The failure message for the expectation.
* @property {String} stack - The stack trace for the failure if available.
* @property {Boolean} passed - Whether the expectation passed or failed.
* @property {Object} expected - Deprecated. If the expectation failed, what was the expected value.
* @property {Object} actual - Deprecated. If the expectation failed, what actual value was produced.
* @property {String|undefined} globalErrorType - The type of an error that
* is reported on the top suite. Valid values are undefined, "afterAll",
* "load", "lateExpectation", and "lateError".
@@ -32,21 +23,12 @@ getJasmineRequireObj().buildExpectationResult = function(j$) {
};
if (!result.passed) {
result.expected = options.expected;
result.actual = options.actual;
if (options.error && !j$.isString_(options.error)) {
if ('code' in options.error) {
result.code = options.error.code;
}
if (
options.error.code === 'ERR_ASSERTION' &&
options.expected === '' &&
options.actual === ''
) {
result.expected = options.error.expected;
result.actual = options.error.actual;
if (options.error.code === 'ERR_ASSERTION') {
result.matcherName = 'assert ' + options.error.operator;
}
}