diff --git a/packages/driver/src/cy/commands/traversals.coffee b/packages/driver/src/cy/commands/traversals.coffee index 173d5322259b..f5a9a81df5a5 100644 --- a/packages/driver/src/cy/commands/traversals.coffee +++ b/packages/driver/src/cy/commands/traversals.coffee @@ -7,12 +7,12 @@ traversals = "find filter not children eq closest first last next nextAll nextUn module.exports = (Commands, Cypress, cy, state, config) -> _.each traversals, (traversal) -> Commands.add traversal, { prevSubject: "element" }, (subject, arg1, arg2, options) -> - if _.isObject(arg2) - options = arg2 - - if _.isObject(arg1) + if _.isObject(arg1) and not _.isFunction(arg1) options = arg1 + if _.isObject(arg2) and not _.isFunction(arg2) + options = arg2 + options ?= {} _.defaults options, {log: true} diff --git a/packages/driver/test/cypress/integration/commands/traversals_spec.coffee b/packages/driver/test/cypress/integration/commands/traversals_spec.coffee index 502f23abea65..5a11b413a116 100644 --- a/packages/driver/test/cypress/integration/commands/traversals_spec.coffee +++ b/packages/driver/test/cypress/integration/commands/traversals_spec.coffee @@ -19,7 +19,9 @@ describe "src/cy/commands/traversals", -> fns = [ {find: "*"} {filter: ":first"} + {filter: (i) -> i == 0} {not: "div"} + {not: (i, e) -> e.tagName == 'div'} {eq: 0} {closest: "body"} "children", "first", "last", "next", "nextAll", "nextUntil", "parent", "parents", "parentsUntil", "prev", "prevAll", "prevUntil", "siblings" @@ -137,15 +139,22 @@ describe "src/cy/commands/traversals", -> it "has a custom message", -> cy.get("#list")[name](arg).then -> - arg = if _.isUndefined(arg) then "" else arg.toString() + if _.isUndefined(arg) or _.isFunction(arg) + message = "" + else + message = arg.toString() + lastLog = @lastLog - expect(lastLog.get("message")).to.eq arg + expect(lastLog.get("message")).to.eq message it "#consoleProps", -> cy.get("#list")[name](arg).then ($el) -> obj = {Command: name} - obj.Selector = [].concat(arg).join(", ") unless _.isFunction(arg) + if _.isFunction(arg) + obj.Selector = "" + else + obj.Selector = [].concat(arg).join(", ") yielded = Cypress.dom.getElements($el) @@ -157,6 +166,12 @@ describe "src/cy/commands/traversals", -> expect(@lastLog.invoke("consoleProps")).to.deep.eq obj + it "can be turned off", -> + cy.get("#list")[name](arg, {log: false}).then -> + lastLog = @lastLog + + expect(lastLog.get("name")).to.eq "get" + it "eventually resolves", -> cy.on "command:retry", _.after 2, -> cy.$$("button:first").text("foo").addClass("bar")