Skip to content

Commit

Permalink
chore: Re-organize tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
sainthkh committed May 2, 2022
1 parent a47b45f commit febf2d3
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

0 comments on commit febf2d3

Please sign in to comment.