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

Commit

Permalink
fix: provide jQuery-wrapped elements to upcoming assertions (#35)
Browse files Browse the repository at this point in the history
* chore: add a test case for yielded primitives

* feat: yield jQuery-wrapped elements to upcoming assertions
  • Loading branch information
badeball authored and bahmutov committed Apr 26, 2019
1 parent 2d6eea6 commit 5afe28d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
12 changes: 12 additions & 0 deletions cypress/integration/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ describe('cypress-xpath', () => {
})
})

it('returns primitives as is', () => {
cy.xpath('string(//h1)').then(el$ => {
expect(el$).to.not.have.property('jquery')
})
})

it('provides jQuery wrapped elements to assertions', () => {
cy.xpath('//h1').should(el$ => {
expect(el$).to.have.property('jquery')
})
})

it('gets h1 text', () => {
cy.xpath('//h1/text()')
.its('0.textContent')
Expand Down
8 changes: 4 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ const xpath = (selector, options = {}) => {

const resolveValue = () => {
return Cypress.Promise.try(getValue).then(value => {
if (!isPrimitive(value)) {
value = Cypress.$(value)
}
return cy.verifyUpcomingAssertions(value, options, {
onRetry: resolveValue,
})
Expand All @@ -107,10 +110,7 @@ const xpath = (selector, options = {}) => {
return resolveValue().then((value) => {
// TODO set found elements on the command log?
Cypress.log(log)
if (isPrimitive(value)) {
return value
}
return Cypress.$(value)
return value
})


Expand Down

0 comments on commit 5afe28d

Please sign in to comment.