Skip to content

Commit

Permalink
driver: fixes #1156 ensure that spies and stubs and primitives retry …
Browse files Browse the repository at this point in the history
…when used as an alias
  • Loading branch information
brian-mann committed Feb 11, 2018
1 parent 6d90862 commit 5069b8d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
19 changes: 14 additions & 5 deletions packages/driver/src/cy/commands/querying.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -120,27 +120,31 @@ module.exports = (Commands, Cypress, cy, state, config) ->
obj = {}

if aliasType is "dom"
_.extend obj,
_.extend(obj, {
$el: value
numRetries: options._retries
})

obj.consoleProps = ->
key = if aliasObj then "Alias" else "Selector"
consoleProps[key] = selector

switch aliasType
when "dom"
_.extend consoleProps,
_.extend(consoleProps, {
Yielded: $dom.getElements(value)
Elements: value?.length
})

when "primitive"
_.extend consoleProps,
_.extend(consoleProps, {
Yielded: value
})

when "route"
_.extend consoleProps,
_.extend(consoleProps, {
Yielded: value
})

return consoleProps

Expand Down Expand Up @@ -203,7 +207,12 @@ module.exports = (Commands, Cypress, cy, state, config) ->
else
## log as primitive
log(subject, "primitive")
return subject

do verifyAssertions = =>
cy.verifyUpcomingAssertions(subject, options, {
ensureExistenceFor: false
onRetry: verifyAssertions
})

start("dom")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,7 @@ describe "src/cy/commands/agents", ->
expect(consoleProps["Alias"]).to.eql("myStub")

it "updates the displayName of the agent", ->
cy.then ->
expect(@myStub.displayName).to.eq("myStub")
expect(@myStub.displayName).to.eq("myStub")

it "stores the lookup as an alias", ->
expect(cy.state("aliases").myStub).to.be.defined
Expand All @@ -236,8 +235,13 @@ describe "src/cy/commands/agents", ->
expect(cy.state("aliases").myStub.subject).to.eq(@stub)

it "assigns subject to runnable ctx", ->
cy.then ->
expect(@myStub).to.eq(@stub)
expect(@myStub).to.eq(@stub)

it "retries until assertions pass", ->
cy.on "command:retry", _.after 2, =>
@myStub("foo")

cy.get("@myStub").should("be.calledWith", "foo")

describe "errors", ->
_.each [null, undefined, {}, [], 123], (value) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ describe "src/cy/commands/aliasing", ->
cy.get("#list li").eq(0).as("firstLi").then ($li) ->
expect($li).to.match li

it "retries primitives and assertions", ->
obj = {}

cy.on "command:retry", _.after 2, ->
obj.foo = "bar"

cy.wrap(obj).as("obj")

cy.get("@obj").should("deep.eq", { foo: "bar" })

context "DOM subjects", ->
it "assigns the remote jquery instance", ->
obj = {}
Expand Down

0 comments on commit 5069b8d

Please sign in to comment.