Skip to content

Commit 6e4b780

Browse files
fix: display the correct expected length in the Command Log when using 'not.have.length' (#33064)
1 parent 19b031f commit 6e4b780

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

cli/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ _Released 12/16/2025 (PENDING)_
1212

1313
- Fixed an issue where a EPIPE error shows up after CTRL+C is done in terminal. Fixes [#30659](https://github.com/cypress-io/cypress/issues/30659). Addressed in [#32873](https://github.com/cypress-io/cypress/pull/32873).
1414
- Fixed an issue where the browser would freeze when Cypress intercepts a synchronous XHR request and a `routeHandler` is used. Fixes [#32874](https://github.com/cypress-io/cypress/issues/32874). Addressed in [#32925](https://github.com/cypress-io/cypress/pull/32925).
15+
- Fixed an issue where the error message for `not.have.length` was not correctly displaying the expected length in the Command Log. Addressed in [#18927](https://github.com/cypress-io/cypress/issues/18927).
1516

1617
## 15.7.1
1718

packages/driver/cypress/e2e/commands/assertions.cy.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,6 +1571,34 @@ describe('src/cy/commands/assertions', () => {
15711571
cy.get('body').should('have.length', 2)
15721572
})
15731573

1574+
it('formats _obj with cypress for `not.have.length`', (done) => {
1575+
cy.on('log:added', (attrs, log) => {
1576+
if (attrs.name === 'assert') {
1577+
cy.removeAllListeners('log:added')
1578+
1579+
expect(log.get('message')).to.eq('expected **<button>** to not have a length of **2**')
1580+
1581+
done()
1582+
}
1583+
})
1584+
1585+
cy.get('button:first').should('not.have.length', 2)
1586+
})
1587+
1588+
it('formats error _obj with cypress for `not.have.length`', (done) => {
1589+
cy.on('log:added', (attrs, log) => {
1590+
if (attrs.name === 'assert') {
1591+
cy.removeAllListeners('log:added')
1592+
1593+
expect(log.get('_error').message).to.eq('expected \'<body>\' to not have a length of 1')
1594+
1595+
done()
1596+
}
1597+
})
1598+
1599+
cy.get('body').should('not.have.length', 1)
1600+
})
1601+
15741602
it('does not touch non DOM objects', () => {
15751603
cy.noop([1, 2, 3]).should('have.length', 3)
15761604
})

packages/driver/src/cy/chai.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ chai.use((chai, u) => {
344344
return this.assert(
345345
obj.length === length,
346346
`expected '${node}' to have a length of \#{exp} but got \#{act}`,
347-
`expected '${node}' to not have a length of \#{act}`,
347+
`expected '${node}' to not have a length of \#{exp}`,
348348
length,
349349
obj.length,
350350
)

0 commit comments

Comments
 (0)