Skip to content

Commit

Permalink
Improvement for assertion following failed traversal
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueWinds committed Oct 17, 2022
1 parent e1e7eca commit 652fd06
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions packages/driver/cypress/e2e/commands/assertions.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2072,6 +2072,20 @@ describe('src/cy/commands/assertions', () => {

cy.wrap(undefined).should('have.value', 'somevalue')
})

it('shows subject instead of undefined when a previous traversal errors', (done) => {
cy.on('log:added', (attrs, log) => {
if (attrs.name === 'assert') {
cy.removeAllListeners('log:added')
expect(log.get('message')).to.eq('expected **subject** to have class **updated**')
done()
}
})

cy.get('body')
.contains('Does not exist')
.should('have.class', 'updated')
})
})

context('descendants', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/driver/src/cypress/chai_jquery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const $chaiJquery = (chai, chaiUtils, callbacks: Callbacks) => {
// From jQuery 3.x .selector API is deprecated. (https://api.jquery.com/selector/)
// Because of that, wrap() above removes selector property.
// That's why we're caching the value of selector above and using it here.
ctx._obj = selector
ctx._obj = selector ?? 'subject'
// if no element found, fail the existence check
// depends on the negate flag
ctx.assert(!!ctx.__flags.negate, ...args)
Expand Down

0 comments on commit 652fd06

Please sign in to comment.