Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d837b0d

Browse files
ryan-snydergrabartley
ryan-snyder
authored andcommittedOct 6, 2019
* Addresses cypress-io#2953 * Added proper test for new error message * Didn't realize it ran this test as well, whoops * Implementing changes as suggested by @jennifer-shehane * Fixing tests and error output. Moved the checks to the start of the get command to ensure we always catch improper options * Removing issue test since the querying spec covers it * Using coffescript isArray check
1 parent 3d5cf50 commit d837b0d

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed
 

‎packages/driver/src/cy/commands/querying.coffee

+5-3
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ module.exports = (Commands, Cypress, cy, state, config) ->
6868

6969
get: (selector, options = {}) ->
7070
ctx = @
71-
71+
72+
if options is null or Array.isArray(options) or typeof options isnt 'object' then return $utils.throwErrByPath "get.invalid_options", {
73+
args: { options }
74+
}
7275
_.defaults(options, {
7376
retry: true
7477
withinSubject: cy.state("withinSubject")
@@ -78,7 +81,6 @@ module.exports = (Commands, Cypress, cy, state, config) ->
7881
})
7982

8083
consoleProps = {}
81-
8284
start = (aliasType) ->
8385
return if options.log is false
8486

@@ -467,4 +469,4 @@ module.exports = (Commands, Cypress, cy, state, config) ->
467469
cy.state("withinSubject", null)
468470

469471
return subject
470-
})
472+
})

‎packages/driver/src/cypress/error_messages.coffee

+1
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ module.exports = {
292292
get:
293293
alias_invalid: "'{{prop}}' is not a valid alias property. Only 'numbers' or 'all' is permitted."
294294
alias_zero: "'0' is not a valid alias property. Are you trying to ask for the first response? If so write @{{alias}}.1"
295+
invalid_options: "#{cmd('get')} only accepts an options object for its second argument. You passed {{options}}"
295296

296297
getCookie:
297298
invalid_argument: "#{cmd('getCookie')} must be passed a string argument for name."

‎packages/driver/test/cypress/integration/commands/querying_spec.coffee

+7
Original file line numberDiff line numberDiff line change
@@ -1173,7 +1173,14 @@ describe "src/cy/commands/querying", ->
11731173
.server()
11741174
.route(/users/, {}).as("getUsers")
11751175
.get("@getUsers.all ")
1176+
_.each ["", "foo", [], 1, null ], (value) =>
1177+
it "throws when options property is not an object. Such as: #{value}", (done) ->
1178+
cy.on "fail", (err) ->
1179+
expect(err.message).to.include "only accepts an options object for its second argument. You passed #{value}"
1180+
done()
11761181

1182+
cy.get("foobar", value)
1183+
11771184
it "logs out $el when existing $el is found even on failure", (done) ->
11781185
button = cy.$$("#button").hide()
11791186

0 commit comments

Comments
 (0)
Please sign in to comment.