Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Chai 4 #2862

Merged
merged 9 commits into from
Dec 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/driver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"bootstrap": "^3.3.5",
"bytes": "^3.0.0",
"card": "^1.0.2",
"chai": "3.5.0",
"chai": "4.2.0",
"chai-as-promised": "6.0.0",
"chokidar-cli": "^1.2.0",
"clone": "^2.1.1",
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 @@ -41,7 +41,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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works for proxies or regular objects, but I don't love it. Would love any ideas for alternatives!

args = if hasSpreadArray then args else [args]

## name could be invoke or its!
name = state("current").get("name")
Expand Down
5 changes: 4 additions & 1 deletion packages/driver/src/dom/jquery.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ unwrap = (obj) ->
isJquery = (obj) ->
## does it have the jquery property and is the
## constructor a function?
!!(obj and obj.jquery and _.isFunction(obj.constructor))
try
hasJqueryProperty = "jquery" in obj or obj?.jquery

!!(hasJqueryProperty and _.isFunction(obj.constructor))

## doing a little jiggle wiggle here
## to avoid circular dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ describe "src/cy/commands/agents", ->
expect(@myStub.displayName).to.eq("myStub")

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

it "stores the agent as the subject", ->
expect(cy.state("aliases").myStub.subject).to.eq(@stub)
Expand Down
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 @@ -337,7 +337,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 @@ -1536,11 +1536,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 @@ -1588,7 +1588,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 @@ -1613,7 +1613,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 @@ -18,7 +18,7 @@ describe "src/cy/commands/querying", ->
it "returns the activeElement", ->
$button = cy.$$("#button")
$button.get(0).focus()

expect(cy.state("document").activeElement).to.eq($button.get(0))

cy.focused().then ($focused) ->
Expand Down Expand Up @@ -434,7 +434,7 @@ describe "src/cy/commands/querying", ->

context "#get", ->
beforeEach ->
Cypress.config("defaultCommandTimeout", 100)
Cypress.config("defaultCommandTimeout", 200)

it "finds by selector", ->
list = cy.$$("#list")
Expand Down Expand Up @@ -477,12 +477,12 @@ describe "src/cy/commands/querying", ->
## still passes because the total running time is
## not factored in (which is correct)
cy
.wait(200)
.get("#missing-el", {timeout: 125})
.wait(400)
.get("#missing-el", {timeout: 225})
.then ->
## it should reset the timeout back
## to 100 after successfully finished get method
expect(cy.timeout()).to.eq(100)
## to 200 after successfully finished get method
expect(cy.timeout()).to.eq(200)

it "cancels existing promises", (done) ->
cy.stub(Cypress.runner, "stop")
Expand Down
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 @@ -50,4 +50,4 @@ 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')