Long String Truncation Omits Failure Cause in Message
Long String Truncation Omits Failure Cause in Message
Long failure messages get truncated and omit the culprit.
Current Behavior
When using:
expect(a).toBe(b);And a and b are long strings, the cause of failure can be elided in the reported message, due to the truncation mechanism. For example, if a='abcdefgh...' and b='abcdefgh...(5000 equal characters)x', the reported message omits the different 'x', present in b and not in a, as follows:
'Expected abcdefgh...(truncated at character 1000) to equal abcdefgh...(truncated at character 1000)'If you use the reproduction suite below, you will find that the message that gets printed to the console with jasmine-spec-reporter will show the same string for the expected and the actual values!
Expected Behavior
Failure message should highlight the culprit. Following the above example, it should report something like:
'Expected [4020 omitted characters ...]bcdefghijklmnopqrstx to equal [4020 omitted characters ...]bcdefghijklmnopqrst'
Suite that reproduces the behavior (for bugs)
describe('repro test', () => {
it('should give a decent message', () => {
let filled = 'abcdefghijklmnopqrstuvwxyz';
filled = filled + filled + filled;
let q = 1;
let r = 1;
const arr = new Array(10000).fill(0).map((x, i) => {
q = (q * 31) % 67;
r = (r * 17) % 31;
return filled.substring(q, q + r);
});
const s1 = arr.join('\n');
arr[9876] += 'x';
const s2 = arr.join('\n');
expect(s1).toEqual(s2);
});
});Context
Not showing the relevant piece of content that caused an assertion to fail slows down programming: one needs to devise ways to be able to know what is the failure culprit.
Source: jasmine/jasmine