diff --git a/packages/driver/cypress/integration/commands/assertions_spec.js b/packages/driver/cypress/integration/commands/assertions_spec.js index 6318a04a4e1b..74a48e597732 100644 --- a/packages/driver/cypress/integration/commands/assertions_spec.js +++ b/packages/driver/cypress/integration/commands/assertions_spec.js @@ -1151,7 +1151,7 @@ describe('src/cy/commands/assertions', () => { }) }) - context('format quotation marks', () => { + describe('message formatting', () => { const expectMarkdown = (test, message, done) => { cy.then(() => { test() @@ -1168,70 +1168,83 @@ describe('src/cy/commands/assertions', () => { }) } - it('preserves quotation marks in number strings', (done) => { - expectMarkdown(() => { - try { - expect(25).to.eq('25') - } catch (error) {} /* eslint-disable-line no-empty */ - }, - `expected **25** to equal **'25'**`, - done) - }) - - it('preserves quotation marks in empty string', (done) => { - expectMarkdown(() => { - try { - expect(42).to.eq('') - } catch (error) {} /* eslint-disable-line no-empty */ - }, - `expected **42** to equal **''**`, - done) - }) + // https://github.com/cypress-io/cypress/issues/19116 + it('text with backslashes', (done) => { + const text = '" { expectMarkdown( - () => expect(`\'cypress\'`).to.eq(`\'cypress\'`), - // ****'cypress'**** -> ** for emphasizing result string + ** for emphasizing the entire result. - `expected **'cypress'** to equal ****'cypress'****`, + () => expect(text).to.equal(text), + `expected **" { - expectMarkdown( - () => { - cy.get('body').then(($body) => { - expect($body).to.contain('div') - }) + describe('messages with quotation marks', () => { + it('preserves quotation marks in number strings', (done) => { + expectMarkdown(() => { + try { + expect(25).to.eq('25') + } catch (error) {} /* eslint-disable-line no-empty */ }, - `expected **** to contain **div**`, - done, - ) - }) + `expected **25** to equal **'25'**`, + done) + }) - it('removes quotation marks in strings', (done) => { - expectMarkdown(() => expect('cypress').to.eq('cypress'), `expected **cypress** to equal **cypress**`, done) - }) + it('preserves quotation marks in empty string', (done) => { + expectMarkdown(() => { + try { + expect(42).to.eq('') + } catch (error) {} /* eslint-disable-line no-empty */ + }, + `expected **42** to equal **''**`, + done) + }) - it('removes quotation marks in objects', (done) => { - expectMarkdown( - () => expect({ foo: 'bar' }).to.deep.eq({ foo: 'bar' }), - `expected **{ foo: bar }** to deeply equal **{ foo: bar }**`, - done, - ) - }) + it('preserves quotation marks if escaped', (done) => { + expectMarkdown( + () => expect(`\'cypress\'`).to.eq(`\'cypress\'`), + // ****'cypress'**** -> ** for emphasizing result string + ** for emphasizing the entire result. + `expected **'cypress'** to equal ****'cypress'****`, + done, + ) + }) - it('formats keys properly for "have.all.keys"', (done) => { - const person = { - name: 'Joe', - age: 20, - } + it('removes quotation marks in DOM elements', (done) => { + expectMarkdown( + () => { + cy.get('body').then(($body) => { + expect($body).to.contain('div') + }) + }, + `expected **** to contain **div**`, + done, + ) + }) - expectMarkdown( - () => expect(person).to.have.all.keys('name', 'age'), - `expected **{ name: Joe, age: 20 }** to have keys **name**, and **age**`, - done, - ) + it('removes quotation marks in strings', (done) => { + expectMarkdown(() => expect('cypress').to.eq('cypress'), `expected **cypress** to equal **cypress**`, done) + }) + + it('removes quotation marks in objects', (done) => { + expectMarkdown( + () => expect({ foo: 'bar' }).to.deep.eq({ foo: 'bar' }), + `expected **{ foo: bar }** to deeply equal **{ foo: bar }**`, + done, + ) + }) + + it('formats keys properly for "have.all.keys"', (done) => { + const person = { + name: 'Joe', + age: 20, + } + + expectMarkdown( + () => expect(person).to.have.all.keys('name', 'age'), + `expected **{ name: Joe, age: 20 }** to have keys **name**, and **age**`, + done, + ) + }) }) describe('formats strings with spaces', (done) => { @@ -1269,36 +1282,6 @@ describe('src/cy/commands/assertions', () => { }) }) - // TODO: this suite should be merged with the suite above - describe('message formatting', () => { - const expectMarkdown = (test, message, done) => { - cy.then(() => { - test() - }) - - cy.on('log:added', (attrs, log) => { - if (attrs.name === 'assert') { - cy.removeAllListeners('log:added') - - expect(log.get('message')).to.eq(message) - - done() - } - }) - } - - // https://github.com/cypress-io/cypress/issues/19116 - it('text with backslashes', (done) => { - const text = '" expect(text).to.equal(text), - `expected **" { beforeEach(function () { this.$body = cy.$$('body')