Skip to content

Commit 1fa3e7f

Browse files
fix: Fix issue with display of assertions when using custom messages (#29243)
* fix: added optional custom message to regex * add changelog entry * Update packages/reporter/cypress/e2e/unit/formatted_message.cy.ts * moved changelog entry to new cypress version --------- Co-authored-by: Jennifer Shehane <[email protected]> Co-authored-by: Jennifer Shehane <[email protected]>
1 parent 96b14c3 commit 1fa3e7f

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

cli/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ _Released 4/16/2024 (PENDING)_
1010

1111
**Bugfixes:**
1212

13+
- Fixed an issue where asserts with custom messages weren't displaying properly. Fixes [#29167](https://github.com/cypress-io/cypress/issues/29167)
1314
- Fixed and issue where cypress launch arguments were not being escaped correctly with multiple values inside quotes. Fixes [#27454](https://github.com/cypress-io/cypress/issues/27454).
1415

1516

packages/reporter/cypress/e2e/unit/formatted_message.cy.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@ describe('formattedMessage', () => {
8585

8686
expect(result).to.equal('expected <strong>&lt;button#increment&gt;</strong> to be enabled')
8787
})
88+
89+
it('renders the custom message properly with the assertion message', () => {
90+
const specialMessage = 'My Custom Message: expected **abcdef** to equal **abcdef**'
91+
const result = formattedMessage(specialMessage, 'assert')
92+
93+
expect(result).to.equal('My Custom Message: expected <strong>abcdef</strong> to equal <strong>abcdef</strong>')
94+
})
8895
})
8996

9097
describe('when command that accepts url', () => {

packages/reporter/src/commands/command.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ const asterisksRegex = /^\*\*(.+?)\*\*$/gs
3535
// 'expected **<span>** to exist in the DOM'
3636
// `expected **glob*glob** to contain *****`
3737
// `expected **<span>** to have CSS property **background-color** with the value **rgb(0, 0, 0)**, but the value was **rgba(0, 0, 0, 0)**`
38-
const assertionRegex = /expected | to[^\*]+| not[^\*]+| with[^\*]+|, but[^\*]+/g
38+
const assertionRegex = /.*expected | to[^\*]+| not[^\*]+| with[^\*]+|, but[^\*]+/g
3939

4040
// used to format the display of command messages and error messages
4141
// we use markdown syntax within our error messages (code ticks, urls, etc)
4242
// and cy.log and Cypress.log supports markdown formatting
4343
export const formattedMessage = (message: string, name?: string) => {
4444
if (!message) return ''
4545

46-
// the command message is formatted as 'expected <actual> to {assertion} <expected>'
46+
// the command message is formatted as '(Optional Custom Msg:) expected <actual> to {assertion} <expected>'
4747
const assertionArray = message.match(assertionRegex)
4848

4949
const expectedActualArray = () => {

0 commit comments

Comments
 (0)