Skip to content

Commit

Permalink
Add quotes around strings in invoking child without parent error (#2713)
Browse files Browse the repository at this point in the history
- Fixes #2684
  • Loading branch information
lilaconlee authored and chrisbreiding committed Nov 20, 2018
1 parent e31b356 commit 599785f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
3 changes: 2 additions & 1 deletion packages/driver/src/cypress/cy.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -458,10 +458,11 @@ create = (specWindow, Cypress, Cookies, state, config, log) ->
## if we have a prevSubject then error
## since we're invoking this improperly
if prevSubject and ("optional" not in [].concat(prevSubject))
stringifiedArg = $utils.stringifyActual(args[0])
$utils.throwErrByPath("miscellaneous.invoking_child_without_parent", {
args: {
cmd: name
args: $utils.stringifyActual(args[0])
args: if _.isString(args[0]) then "\"#{stringifiedArg}\"" else stringifiedArg
}
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ describe "src/cy/commands/aliasing", ->
it "throws as a parent command", (done) ->
cy.on "fail", (err) ->
expect(err.message).to.include("before running a parent command")
expect(err.message).to.include("cy.as(foo)")
expect(err.message).to.include("cy.as(\"foo\")")
done()

cy.as("foo")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ describe "src/cy/commands/connectors", ->

it "throws without a subject", (done) ->
cy.on "fail", (err) ->
expect(err.message).to.include("cy.invoke(queue)")
expect(err.message).to.include("cy.invoke(\"queue\")")
expect(err.message).to.include("child command before running a parent command")
done()

Expand Down Expand Up @@ -728,7 +728,7 @@ describe "src/cy/commands/connectors", ->

it "throws without a subject", (done) ->
cy.on "fail", (err) ->
expect(err.message).to.include("cy.its(wat)")
expect(err.message).to.include("cy.its(\"wat\")")
expect(err.message).to.include("child command before running a parent command")
done()

Expand Down
11 changes: 10 additions & 1 deletion packages/driver/test/cypress/integration/cypress/cy_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,15 @@ describe "driver/src/cypress/cy", ->
cy.wrap("foo")
cy.c()

it "fails when calling child command before parent with arguments", (done) ->
cy.on "fail", (err) ->
expect(err.message).to.include("Oops, it looks like you are trying to call a child command before running a parent command")
expect(err.message).to.include("cy.c(\"bar\")")
done()

cy.wrap("foo")
cy.c("bar")

it "fails when previous subject becomes detached", (done) ->
cy.$$("button:first").click ->
$(@).remove()
Expand Down Expand Up @@ -322,4 +331,4 @@ describe "driver/src/cypress/cy", ->

it "updates state('current') with modified args", ->
cy.get("form").eq(0).submit().then =>
expect(cy.state("current").get("prev").get("args")[0].foo).to.equal("foo")
expect(cy.state("current").get("prev").get("args")[0].foo).to.equal("foo")

0 comments on commit 599785f

Please sign in to comment.