Skip to content
This repository has been archived by the owner on Oct 13, 2022. It is now read-only.

Commit

Permalink
feat: enable conditional logging (#40)
Browse files Browse the repository at this point in the history
Co-authored-by: Gleb Bahmutov <[email protected]>
  • Loading branch information
badeball and bahmutov authored May 26, 2020
1 parent 1efe42e commit cbcc011
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ This explanation was shamelessly copied from [teamcapybara/capybara][capybara-xp
- [x] retry the assertion that follows [#3](https://github.com/cypress-io/cypress-xpath/issues/3)
- [x] add TypeScript definitions [#4](https://github.com/cypress-io/cypress-xpath/issues/4)
- [ ] search from the previous subject element [#5](https://github.com/cypress-io/cypress-xpath/issues/5)
- [ ] log or not, depending on user option [#19](https://github.com/cypress-io/cypress-xpath/issues/19)
- [x] log or not, depending on user option [#19](https://github.com/cypress-io/cypress-xpath/issues/19)

## License

Expand Down
22 changes: 22 additions & 0 deletions cypress/integration/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,26 @@ describe('cypress-xpath', () => {
})
})
})

context('logging', () => {
beforeEach(() => {
cy.visit('cypress/integration/index.html')
})

it('should log by default', () => {
cy.spy(Cypress, 'log').log(false)

cy.xpath('//h1').then(() => {
expect(Cypress.log).to.be.calledWithMatch({ name: 'xpath' })
})
})

it('should not log when provided log: false', () => {
cy.spy(Cypress, 'log').log(false)

cy.xpath('//h1', { log: false }).then(() => {
expect(Cypress.log).to.not.be.calledWithMatch({ name: 'xpath' })
})
})
})
})
6 changes: 4 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,10 @@ const xpath = (subject, selector, options = {}) => {
}

return resolveValue().then((value) => {
// TODO set found elements on the command log?
Cypress.log(log)
if (options.log !== false) {
// TODO set found elements on the command log?
Cypress.log(log)
}
return value
})

Expand Down

0 comments on commit cbcc011

Please sign in to comment.