driver: fixes #1156 ensure that spies and stubs and primitives retry when used as an alias (#1294)

This commit is contained in:
Brian Mann
2018-02-11 16:05:57 -05:00
committed by GitHub
parent b8c1dbc703
commit 386bed4480
3 changed files with 32 additions and 9 deletions
@@ -120,9 +120,10 @@ 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"
@@ -130,17 +131,20 @@ module.exports = (Commands, Cypress, cy, state, config) ->
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
@@ -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")
@@ -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
@@ -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) =>
@@ -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 = {}