Skip to content

Commit

Permalink
chore: Re-organize tests in assertions_spec.js (#21283)
Browse files Browse the repository at this point in the history
Co-authored-by: Zach Bloomquist <git@chary.us>
  • Loading branch information
sainthkh and flotwig committed May 6, 2022
1 parent d1436ee commit 331e541
Showing 1 changed file with 67 additions and 84 deletions.
151 changes: 67 additions & 84 deletions packages/driver/cypress/integration/commands/assertions_spec.js
Expand Up @@ -1151,7 +1151,7 @@ describe('src/cy/commands/assertions', () => {
})
})

context('format quotation marks', () => {
describe('message formatting', () => {
const expectMarkdown = (test, message, done) => {
cy.then(() => {
test()
Expand All @@ -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 = '"<OE_D]dQ\\'

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'****`,
() => expect(text).to.equal(text),
`expected **"<OE_D]dQ\\\\** to equal **"<OE_D]dQ\\\\**`,
done,
)
})

it('removes quotation marks in DOM elements', (done) => {
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 **<body>** 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 **<body>** 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) => {
Expand Down Expand Up @@ -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 = '"<OE_D]dQ\\'

expectMarkdown(
() => expect(text).to.equal(text),
`expected **"<OE_D]dQ\\\\** to equal **"<OE_D]dQ\\\\**`,
done,
)
})
})

context('chai overrides', () => {
beforeEach(function () {
this.$body = cy.$$('body')
Expand Down

3 comments on commit 331e541

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 331e541 May 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/9.6.1/linux-x64/develop-331e5412f566490e75d45d52d8111836745c336c/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 331e541 May 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/9.6.1/darwin-x64/develop-331e5412f566490e75d45d52d8111836745c336c/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 331e541 May 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the win32 x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/9.6.1/win32-x64/develop-331e5412f566490e75d45d52d8111836745c336c/cypress.tgz

Please sign in to comment.