From d837b0deca2819ddb381f70c33458fc7b8dab117 Mon Sep 17 00:00:00 2001 From: ryan-snyder <36665494+ryan-snyder@users.noreply.github.com> Date: Mon, 23 Sep 2019 14:47:51 -0300 Subject: [PATCH] Addresses #2953 (#5174) * Addresses #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 --- packages/driver/src/cy/commands/querying.coffee | 8 +++++--- packages/driver/src/cypress/error_messages.coffee | 1 + .../cypress/integration/commands/querying_spec.coffee | 7 +++++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/driver/src/cy/commands/querying.coffee b/packages/driver/src/cy/commands/querying.coffee index 934edb0b584a..25ddb2fcf4fd 100644 --- a/packages/driver/src/cy/commands/querying.coffee +++ b/packages/driver/src/cy/commands/querying.coffee @@ -68,7 +68,10 @@ module.exports = (Commands, Cypress, cy, state, config) -> get: (selector, options = {}) -> ctx = @ - + + if options is null or Array.isArray(options) or typeof options isnt 'object' then return $utils.throwErrByPath "get.invalid_options", { + args: { options } + } _.defaults(options, { retry: true withinSubject: cy.state("withinSubject") @@ -78,7 +81,6 @@ module.exports = (Commands, Cypress, cy, state, config) -> }) consoleProps = {} - start = (aliasType) -> return if options.log is false @@ -467,4 +469,4 @@ module.exports = (Commands, Cypress, cy, state, config) -> cy.state("withinSubject", null) return subject - }) + }) \ No newline at end of file diff --git a/packages/driver/src/cypress/error_messages.coffee b/packages/driver/src/cypress/error_messages.coffee index 58740aed0964..1c98ecfdac07 100644 --- a/packages/driver/src/cypress/error_messages.coffee +++ b/packages/driver/src/cypress/error_messages.coffee @@ -292,6 +292,7 @@ module.exports = { get: alias_invalid: "'{{prop}}' is not a valid alias property. Only 'numbers' or 'all' is permitted." alias_zero: "'0' is not a valid alias property. Are you trying to ask for the first response? If so write @{{alias}}.1" + invalid_options: "#{cmd('get')} only accepts an options object for its second argument. You passed {{options}}" getCookie: invalid_argument: "#{cmd('getCookie')} must be passed a string argument for name." diff --git a/packages/driver/test/cypress/integration/commands/querying_spec.coffee b/packages/driver/test/cypress/integration/commands/querying_spec.coffee index 11c79a85dd82..a6303e9c22f4 100644 --- a/packages/driver/test/cypress/integration/commands/querying_spec.coffee +++ b/packages/driver/test/cypress/integration/commands/querying_spec.coffee @@ -1173,7 +1173,14 @@ describe "src/cy/commands/querying", -> .server() .route(/users/, {}).as("getUsers") .get("@getUsers.all ") + _.each ["", "foo", [], 1, null ], (value) => + it "throws when options property is not an object. Such as: #{value}", (done) -> + cy.on "fail", (err) -> + expect(err.message).to.include "only accepts an options object for its second argument. You passed #{value}" + done() + cy.get("foobar", value) + it "logs out $el when existing $el is found even on failure", (done) -> button = cy.$$("#button").hide()