Skip to content

Commit

Permalink
deprecated cy.wait(fn)
Browse files Browse the repository at this point in the history
  • Loading branch information
brian-mann committed Sep 17, 2015
1 parent 0ce436d commit 0f34bbb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 91 deletions.
30 changes: 1 addition & 29 deletions app/js/api/cypress/cy/commands/waiting.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -45,35 +45,7 @@ $Cypress.register "Waiting", (Cypress, _, $, Promise) ->
.return(subject)

_waitFunction: (subject, fn, options) ->
retry = ->
@invoke2(@prop("current"), fn, options)

stringify = (fn) ->
_.str.clean fn.toString()

try
## invoke fn and make sure its not strictly false
options.value = fn.call(@private("runnable").ctx, subject)
if options.value
## do not think we need to log out waits
## just like we dont log out cy.thens
## if wait blows up and fails then handle that
## at that time
# log({
# "Waited For": stringify(fn)
# Retried: options.retries + " times"
# })
return subject
catch e
options.error = "Could not continue due to: " + e

return @_retry(retry, options)

## retry outside of the try / catch block because
## if retry throws errors we want those to bubble
options.error = "The final value was: " + options.value

@_retry(retry, options) if _.isNull(options.value) or options.value is false
@throwErr("cy.wait(fn) has been deprecated. Instead just change this command to be .should(fn).")

_waitString: (subject, str, options) ->
if options.log isnt false
Expand Down
65 changes: 5 additions & 60 deletions spec/client/api/cy/waiting_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -29,73 +29,18 @@ describe "$Cypress.Cy Waiting Commands", ->
expect(trigger).not.to.be.calledWith "invoke:end"

describe "function argument", ->
it "resolves when truthy", ->
@cy.wait ->
"foo" is "foo"

it "retries when false", (done) ->
i = 0
fn = ->
i += 1
i is 2
fn = @sandbox.spy fn
@cy.wait(fn)
@cy.on "end", ->
expect(fn.callCount).to.eq 2
done()

it "retries when null", (done) ->
i = 0
fn = ->
i += 1
if i isnt 2 then null else true
fn = @sandbox.spy fn
@cy.then(fn).wait(fn)
@cy.on "end", ->
expect(fn.callCount).to.eq 2
done()

it "resolves when undefined", (done) ->
## after returns undefined
fn = -> undefined

fn = @sandbox.spy fn
@cy.wait(fn)

@cy.on "end", ->
expect(fn.callCount).to.eq 1
done()

it "resolves with existing subject", ->
@cy
.get("input").then ($input) ->
@$input = $input
.wait(-> true)

@cy.on "invoke:end", (obj) =>
if obj.name is "wait"
expect(@cy.prop("subject")).to.eq @$input

describe "errors thrown", ->
beforeEach ->
@currentTest.enableTimeouts(false)
@uncaught = @allowErrors()

it "times out eventually due to false value", (done) ->
## forcibly reduce the timeout to 500 ms
## so we dont have to wait so long
@cy.wait (-> false), timeout: 100

@cy.on "fail", (err) ->
expect(err.message).to.include "The final value was: false"
it "is deprecated", (done) ->
@cy.on "fail", (err) =>
expect(err.message).to.eq "cy.wait(fn) has been deprecated. Instead just change this command to be .should(fn)."
done()

it "appends to the err message", (done) ->
@cy.wait (-> expect(true).to.be.false), timeout: 100

@cy.on "fail", (err) ->
expect(err.message).to.include "Timed out retrying: Could not continue due to: AssertionError"
done()
@cy.get("body").wait ($body) ->
expect($body).to.match("body")

describe "alias argument", ->
it "waits for a route alias to have a response", ->
Expand Down
4 changes: 2 additions & 2 deletions spec/client/api/integration/async_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ describe "Async Integration Tests", ->
.get("form").then ($form) ->
expect($form).to.contain("form success!")

it "needs an explicit wait when an element is immediately found", ->
it "needs an explicit should when an element is immediately found", ->
@cy
.server()
.route("POST", "/users", {})
.get("input[name=name]").type("brian")
.get("#submit").click()
.get("form").wait ($form) ->
.get("form").should ($form) ->
expect($form).to.contain("form success!")

0 comments on commit 0f34bbb

Please sign in to comment.