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

Issue #6216 -- have .its() receive the number 0 as parameter #6234

Merged
merged 4 commits into from
Jan 27, 2020
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: 2 additions & 0 deletions packages/driver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ If you want to run tests in Chrome and keep it open after the spec finishes, you

```bash
npm run cypress:run -- --config testFiles=e2e/focus_blur_spec.js --browser chrome --no-exit
```

If you would like to run a particular integration test, see the GUI and poke around during the test, you can an exclusive test like:

```bash
Expand Down
10 changes: 7 additions & 3 deletions packages/driver/src/cy/commands/connectors.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ module.exports = (Commands, Cypress, cy, state, config) ->

return ".#{str}(" + $utils.stringify(args) + ")"

## to allow the falsy value 0 to be used
isProp = (str) -> !!str or str is 0

message = getMessage()

traversalErr = null
Expand All @@ -179,7 +182,8 @@ module.exports = (Commands, Cypress, cy, state, config) ->
consoleProps: ->
Subject: subject

if not str
## check for false positive (negative?) with 0 given as index
if not isProp(str)
$utils.throwErrByPath("invoke_its.null_or_undefined_property_name", {
onFail: options._log
args: { cmd: name, identifier: if isCmdIts then "property" else "function" }
Expand Down Expand Up @@ -253,7 +257,7 @@ module.exports = (Commands, Cypress, cy, state, config) ->

## if we're attempting to tunnel into
## a null or undefined object...
if prop and valIsNullOrUndefined
if isProp(prop) and valIsNullOrUndefined
if index is 0
## give an error stating the current subject is nil
traversalErr = subjectNullOrUndefinedErr(prop, acc)
Expand All @@ -265,7 +269,7 @@ module.exports = (Commands, Cypress, cy, state, config) ->
return acc

## if we have no more properties to traverse
if not prop
if not isProp(prop)
if valIsNullOrUndefined
## set traversal error that the final value is null or undefined
traversalErr = propertyValueNullOrUndefinedErr(previousProp, acc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,16 @@ describe "src/cy/commands/connectors", ->

cy.noop([_.noop, fn]).invoke(1).should('be.true')

it "works with 0 as a value if object has property 0", ->
i = 0
fn = ->
if i++ is 0 then "cy.noop is undocumented"
else "and I don't understand what it is"

cy.wrap([fn, "bar"]).invoke(0).should("eq", "cy.noop is undocumented")
cy.wrap({"0": fn}).invoke(0).should("eq", "and I don't understand what it is")


it "forwards any additional arguments", ->
cy.noop(@obj).invoke("bar", 1, 2).then (num) ->
expect(num).to.eq 3
Expand Down Expand Up @@ -813,6 +823,11 @@ describe "src/cy/commands/connectors", ->
it "works with numerical indexes", ->
cy.wrap(['foo', 'bar']).its(1).should('eq', 'bar')

it "works with 0 as a value if object has property 0", ->
datner marked this conversation as resolved.
Show resolved Hide resolved
cy.wrap(["foo", "bar"]).its(0).should("eq", "foo")
cy.wrap({"0": "whoa"}).its(0).should("eq", "whoa")
cy.wrap([###empty###, "spooky"]).its(0).should("not.exist")

it "reduces into dot separated values", ->
obj = {
foo: {
Expand Down