Skip to content

Commit

Permalink
Upgrade to Chai 4 (#2862)
Browse files Browse the repository at this point in the history
* Initial upgrade changes

* Some quick fixes

* More fixes

* Clean up exp logic and fix spread array failures

* Remove caret from package.json

* Add handling for proxies in isJquery

* iterate on flaky test, increase default command timeout
  • Loading branch information
lilaconlee authored and chrisbreiding committed May 21, 2019
1 parent 3de8a84 commit 25f2a6d
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 27 deletions.
2 changes: 1 addition & 1 deletion packages/driver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"body-parser": "1.19.0",
"bootstrap": "4.3.1",
"bytes": "3.1.0",
"chai": "3.5.0",
"chai": "4.2.0",
"chai-as-promised": "6.0.0",
"chokidar-cli": "1.2.2",
"clone": "2.1.2",
Expand Down
10 changes: 7 additions & 3 deletions packages/driver/src/cy/commands/asserting.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ module.exports = (Commands, Cypress, cy, state, config) ->

## are we doing a length assertion?
if reHaveLength.test(chainers) or reExistence.test(chainers)
exp.isCheckingExistence = true
isCheckingExistence = true

applyChainer = (memo, value) ->
if value is lastChainer
Expand All @@ -108,6 +108,8 @@ module.exports = (Commands, Cypress, cy, state, config) ->
throwAndLogErr(err)
else
throw err
else
memo[value]
else
memo[value]

Expand All @@ -118,10 +120,10 @@ module.exports = (Commands, Cypress, cy, state, config) ->
## because its possible we're asserting about an
## element which has left the DOM and we always
## want to auto-fail on those
if not exp.isCheckingExistence and $dom.isElement(subject)
if not isCheckingExistence and $dom.isElement(subject)
cy.ensureAttached(subject, "should")

_.reduce chainers, (memo, value) =>
newExp = _.reduce chainers, (memo, value) =>
if value not of memo
err = $utils.cypressErr("The chainer: '#{value}' was not found. Could not build assertion.")
err.retry = false
Expand All @@ -131,6 +133,8 @@ module.exports = (Commands, Cypress, cy, state, config) ->

, exp

exp = newExp ? exp

Promise.try(applyChainers).then ->
## if the _obj has been mutated then we
## are chaining assertion properties and
Expand Down
5 changes: 4 additions & 1 deletion packages/driver/src/cy/commands/connectors.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ module.exports = (Commands, Cypress, cy, state, config) ->
remoteSubject = cy.getRemotejQueryInstance(subject)

args = remoteSubject or subject
args = if subject?._spreadArray then args else [args]

try
hasSpreadArray = "_spreadArray" in subject or subject?._spreadArray
args = if hasSpreadArray then args else [args]

## name could be invoke or its!
name = state("current").get("name")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ describe "src/cy/commands/agents", ->
it "retries until assertions pass", ->
cy.on "command:retry", _.after 2, =>
@myStub("foo")

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

describe "errors", ->
Expand All @@ -255,7 +255,7 @@ describe "src/cy/commands/agents", ->
_.each ["test", "runnable", "timeout", "slow", "skip", "inspect"], (blacklist) ->
it "throws on a blacklisted word: #{blacklist}", ->
expect(=> cy.stub().as(blacklist)).to.throw("cy.as() cannot be aliased as: '#{blacklist}'. This word is reserved.")

context "with dots", ->
beforeEach ->
@logs = []
Expand Down Expand Up @@ -296,7 +296,7 @@ describe "src/cy/commands/agents", ->
it "retries until assertions pass", ->
cy.on "command:retry", _.after 2, =>
@["my.stub"]("foo")

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

describe "errors", ->
Expand Down Expand Up @@ -524,4 +524,4 @@ describe "src/cy/commands/agents", ->
expect(@agents.spy).to.be.a("function")
expect(@agents.spy().callCount).to.be.a("number")
expect(@agents.stub).to.be.a("function")
expect(@agents.stub().returns).to.be.a("function")
expect(@agents.stub().returns).to.be.a("function")
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe "src/cy/commands/aliasing", ->

it "stores the lookup as an alias", ->
cy.get("body").as("b").then ->
expect(cy.state("aliases").b).to.be.defined
expect(cy.state("aliases").b).to.exist

it "stores the resulting subject as the alias", ->
$body = cy.$$("body")
Expand Down Expand Up @@ -356,7 +356,7 @@ describe "src/cy/commands/aliasing", ->
.get("input:first").as("firstInput")
.get("div:last").as("lastDiv")
.then ->
expect(cy.getAlias("@firstInput")).to.be.defined
expect(cy.getAlias("@firstInput")).to.exist

describe "errors", ->
it "throws when an alias cannot be found", (done) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ describe "src/cy/commands/assertions", ->
expect(log.invoke("consoleProps")).to.deep.eq {
Command: "assert"
subject: log.get("subject")
Message: "expected <body> to have a property length"
Message: "expected <body> to have property length"
}

done()
Expand Down Expand Up @@ -705,7 +705,7 @@ describe "src/cy/commands/assertions", ->
if attrs.name is "assert"
cy.removeAllListeners("log:added")

expect(log.get("message")).to.eq "expected **<button>** to have a property **length**"
expect(log.get("message")).to.eq "expected **<button>** to have property **length**"
done()

cy.get("button:first").should("have.property", "length")
Expand Down Expand Up @@ -1541,11 +1541,11 @@ describe "src/cy/commands/assertions", ->
)

expect(l2.get("message")).to.eq(
"expected **{ foo: bar, baz: quux }** to have a property **foo**"
"expected **{ foo: bar, baz: quux }** to have property **foo**"
)

expect(l3.get("message")).to.eq(
"expected **{ foo: bar, baz: quux }** to have a property **foo** of **bar**"
"expected **{ foo: bar, baz: quux }** to have property **foo** of **bar**"
)

expect(l4.get("message")).to.eq(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1732,7 +1732,7 @@ describe "src/cy/commands/navigation", ->
expect(@lastLog).to.exist
expect(@lastLog.get("state")).to.eq("pending")
expect(@lastLog.get("message")).to.eq("--waiting for new page to load--")
expect(@lastLog.get("snapshots")).to.be.empty
expect(@lastLog.get("snapshots")).to.not.exist

.get("#dimensions").click()
.then ->
Expand All @@ -1757,7 +1757,7 @@ describe "src/cy/commands/navigation", ->
expect(@lastLog).to.exist
expect(@lastLog.get("state")).to.eq("pending")
expect(@lastLog.get("message")).to.eq("--waiting for new page to load--")
expect(@lastLog.get("snapshots")).to.be.empty
expect(@lastLog.get("snapshots")).to.not.exist

cy
.get("form#click-me")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1661,4 +1661,4 @@ describe "src/cy/commands/querying", ->
cy.on "command:retry", _.after 2, ->
Cypress.stop()

cy.contains(/^does not contain asdfasdf at all$/)
cy.contains(/^does not contain asdfasdf at all$/)
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ describe "src/cy/commands/screenshot", ->
expect(Screenshot.onBeforeScreenshot).to.be.calledOnce
expect(Screenshot.onBeforeScreenshot.firstCall.args[0]).to.match(".tall-element")

expect(Screenshot.onAfterScreenshot).not.to.be.calleed
expect(Screenshot.onAfterScreenshot).not.to.be.called
})
.then ->
expect(Screenshot.onAfterScreenshot).to.be.calledOnce
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ describe "driver/src/cypress/cy", ->
fn = ->
cy.props.foo

expect(fn).to.throw(/You are accessing a private property/)
expect(fn).to.throw(/function: cy.state\(\.\.\.\)/)
expect(fn).to.throw('You are accessing a private property')
expect(fn).to.throw('function: cy.state\(\.\.\.\)')

it "throws on accessing privates", ->
fn = ->
cy.privates.foo

expect(fn).to.throw(/You are accessing a private property/)
expect(fn).to.throw(/function: cy.state\(\.\.\.\)/)
expect(fn).to.throw('You are accessing a private property')
expect(fn).to.throw('function: cy.state\(\.\.\.\)')

context "internals of custom commands", ->
beforeEach ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,17 @@ describe "driver/src/cypress/index", ->
fn = ->
Cypress.Log.command({})

expect(fn).to.throw(/has been renamed to Cypress.log/)
expect(fn).to.throw('has been renamed to Cypress.log')

it "throws when passing non-object to Cypress.log()", ->
fn = ->
Cypress.log('My Log')

expect(fn).to.throw(/Cypress.log() can only be called with an options object. Your argument was/)
expect(fn).to.throw(/My Log/)
expect(fn).to.throw('Cypress.log() can only be called with an options object. Your argument was')
expect(fn).to.throw('My Log')

it "does not throw when Cypress.log() called outside of command", ->
fn = ->
Cypress.log({ message: 'My Log' })

expect(fn).to.not.throw()
expect(fn).not.to.throw()

0 comments on commit 25f2a6d

Please sign in to comment.