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

feat: enable conditional logging #40

Merged
merged 2 commits into from
May 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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