diff --git a/README.md b/README.md index 20634e1..17bce0f 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/cypress/integration/spec.js b/cypress/integration/spec.js index 98492a8..418e59d 100644 --- a/cypress/integration/spec.js +++ b/cypress/integration/spec.js @@ -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' }) + }) + }) + }) }) diff --git a/src/index.js b/src/index.js index 10664f5..a7a4e2f 100644 --- a/src/index.js +++ b/src/index.js @@ -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 })