diff --git a/packages/driver/src/cy/commands/local_storage.coffee b/packages/driver/src/cy/commands/local_storage.coffee index 1088a73270bb..469f022feb0a 100644 --- a/packages/driver/src/cy/commands/local_storage.coffee +++ b/packages/driver/src/cy/commands/local_storage.coffee @@ -30,17 +30,24 @@ module.exports = (Commands, Cypress, cy, state, config) -> null Commands.addAll({ - clearLocalStorage: (keys) -> + clearLocalStorage: (keys, options = {}) -> + if _.isPlainObject(keys) + options = keys + keys = null + + _.defaults options, {log: true} + ## bail if we have keys and we're not a string and we're not a regexp if keys and not _.isString(keys) and not _.isRegExp(keys) $errUtils.throwErrByPath("clearLocalStorage.invalid_argument") remote = clearLocalStorage(state, keys) - Cypress.log - name: "clear ls" - snapshot: true - end: true + if options.log + Cypress.log + name: "clear ls" + snapshot: true + end: true ## return the remote local storage object return remote diff --git a/packages/driver/test/cypress/integration/commands/local_storage_spec.coffee b/packages/driver/test/cypress/integration/commands/local_storage_spec.coffee index 82535d4dfe3a..162cbdebb119 100644 --- a/packages/driver/test/cypress/integration/commands/local_storage_spec.coffee +++ b/packages/driver/test/cypress/integration/commands/local_storage_spec.coffee @@ -40,8 +40,8 @@ describe "src/cy/commands/local_storage", -> cy.on "fail", (err) -> expect(err.message).to.include "cy.clearLocalStorage() must be called with either a string or regular expression." done() - - cy.clearLocalStorage({}) + # A number is used as an object will be considered as `options` + cy.clearLocalStorage(1) describe ".log", -> beforeEach -> @@ -63,3 +63,23 @@ describe "src/cy/commands/local_storage", -> expect(lastLog.get("snapshots").length).to.eq(1) expect(lastLog.get("snapshots")[0]).to.be.an("object") + + describe "without log", -> + beforeEach -> + cy.on "log:added", (attrs, log) => + @lastLog = log + + return null + + it "log is disabled", -> + cy.clearLocalStorage('foo', {log: false}).then -> + lastLog = @lastLog + + expect(lastLog).to.be.undefined + + it "log is disabled without key", -> + cy.clearLocalStorage({log: false}).then -> + lastLog = @lastLog + + expect(lastLog).to.be.undefined +