Skip to content

Commit

Permalink
Fix bug in traversals where passed function is treated as options obj…
Browse files Browse the repository at this point in the history
…ect (#3334)

* Fixed bug where passed function was treated as options object

* Added tests to existing suite
  • Loading branch information
Lakitna authored and chrisbreiding committed Feb 12, 2019
1 parent d3b2384 commit 13ebb97
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
8 changes: 4 additions & 4 deletions packages/driver/src/cy/commands/traversals.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)

Expand All @@ -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")
Expand Down

0 comments on commit 13ebb97

Please sign in to comment.