Skip to content

Commit

Permalink
fix: #3847 only options.log !== false use options._log.error (#4127)
Browse files Browse the repository at this point in the history
* fix: #3847 only options.log !== false use options._log.error

* ADDED issue #3847 behavior test

* fix 3847_spec.js prettier
  • Loading branch information
ZWkang authored and jennifer-shehane committed May 21, 2019
1 parent b6ece46 commit 3eacfeb
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/driver/src/cy/commands/querying.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ module.exports = (Commands, Cypress, cy, state, config) ->
try
$el = cy.$$(selector, options.withinSubject)
catch e
e.onFail = -> options._log.error(e)
e.onFail = -> if options.log is false then e else options._log.error(e)
throw e

## if that didnt find anything and we have a within subject
Expand Down
42 changes: 42 additions & 0 deletions packages/driver/test/cypress/integration/issues/3847_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// https://github.com/cypress-io/cypress/issues/3847
describe('issue 3847', () => {
// global variable
let queryKey = '\'input\''

// like Sizzle throw error
let error = new Error(`Syntax error, unrecognized expression: ${queryKey}`)

beforeEach(() => {
cy.visit('/fixtures/dom.html')
})

it('options default { log: true } should be work without Unhandled rejection', (done) => {
cy.on('fail', (err) => {
expect(err.message).to.eql(error.message)
expect(err.name).to.eql(error.name)
done()

return false
})

// get 'input'
cy.get(queryKey)
})

// Unhandled rejection TypeError: Cannot read property 'error' of undefined
it('options { log: false } will not throw Unhandled rejection', (done) => {

// error should seem like { log: true }
cy.on('fail', (err) => {
expect(err.message).to.eql(error.message)
expect(err.name).to.eql(error.name)
expect(err.message).not.to.match(/Unhandled\srejection\sTypeError/)
done()

return false
})

// get 'input'
cy.get(queryKey, { log: false })
})
})

0 comments on commit 3eacfeb

Please sign in to comment.