Skip to content

Commit

Permalink
update v11 code
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed Oct 15, 2024
1 parent c6528fe commit d66357c
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions src/index-v11.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function getCypressCurrentSubject() {
Cypress.Commands.add(
'if',
{ prevSubject: true },
function (subject, assertion, assertionValue) {
function (subject, assertion, assertionValue1, assertionValue2) {
const cmd = cy.state('current')
debug('if', cmd.attributes, 'subject', subject, 'assertion?', assertion)
debug('next command', cmd.next)
Expand Down Expand Up @@ -86,18 +86,31 @@ Cypress.Commands.add(
const parts = assertion.split('.')
let assertionReduced = expect(subject).to
parts.forEach((assertionPart, k) => {
if (
k === parts.length - 1 &&
typeof assertionValue !== 'undefined'
) {
assertionReduced = assertionReduced[assertionPart](assertionValue)
if (k === parts.length - 1) {
if (
typeof assertionValue1 !== 'undefined' &&
typeof assertionValue2 !== 'undefined'
) {
assertionReduced = assertionReduced[assertionPart](
assertionValue1,
assertionValue2,
)
} else if (typeof assertionValue1 !== 'undefined') {
assertionReduced =
assertionReduced[assertionPart](assertionValue1)
}
} else {
assertionReduced = assertionReduced[assertionPart]
}
})
} else {
if (typeof assertionValue !== 'undefined') {
expect(subject).to.be[assertion](assertionValue)
if (
typeof assertionValue1 !== 'undefined' &&
typeof assertionValue2 !== 'undefined'
) {
expect(subject).to.be[assertion](assertionValue1, assertionValue2)
} else if (typeof assertionValue1 !== 'undefined') {
expect(subject).to.be[assertion](assertionValue1)
} else {
expect(subject).to.be[assertion]
}
Expand Down

0 comments on commit d66357c

Please sign in to comment.