Improve the error message of the toHaveSize matcher.

We include the size of the thing that didn't meet the size expectation.
This commit is contained in:
Stephan Ferlin-Reiter
2024-07-02 20:07:28 +00:00
parent cc69edf92c
commit 6f23e706d7
2 changed files with 32 additions and 4 deletions

View File

@@ -15,6 +15,17 @@ describe('toHaveSize', function() {
expect(result.pass).toBe(false);
});
it('informs about the size of an array whose length does not match', function() {
const matcher = jasmineUnderTest.matchers.toHaveSize({
pp: jasmineUnderTest.makePrettyPrinter()
}),
result = matcher.compare([1, 2, 3], 2);
expect(result.message()).toEqual(
'Expected [ 1, 2, 3 ] with size 3 to have size 2.'
);
});
it('passes for an object with the proper number of keys', function() {
const matcher = jasmineUnderTest.matchers.toHaveSize(),
result = matcher.compare({ a: 1, b: 2 }, 2);