Files
cypress/docs/source/api/commands/clearlocalstorage.md
T
Brian Mann 91bb010fd6 docs: fixes #231, cleanup all the API docs + notes
- go into more detail on trigger vs action commands
- explain actionability further
- better format notes + examples
- consistent no arg / arg examples
- es6 all the functions
- remove duplicated intractability content
- remove simulated events garbage
- go into more detail on pseudo action commands
- much better cy.contains usage
2017-06-30 18:33:52 -04:00

2.2 KiB

title, comments
title comments
clearLocalStorage false

Clear data in local storage.

{% note warning %} Cypress automatically runs this command before each test to prevent state from being shared across tests. You shouldn't need to use this command unless you're using it to clear localStorage inside a single test. {% endnote %}

Syntax

cy.clearLocalStorage()
cy.clearLocalStorage(key)
cy.clearLocalStorage(options)
cy.clearLocalStorage(keys, options)

Usage

{% fa fa-check-circle green %} Correct Usage

cy.clearLocalStorage()  // clear all local storage

Arguments

{% fa fa-angle-right %} keys (String, RegExp)

Specify key to be cleared in local storage.

{% fa fa-angle-right %} options (Object)

Pass in an options object to change the default behavior of cy.clearLocalStorage().

Option Default Description
log true {% usage_options log %}

Yields {% helper_icon yields %}

{% yields null cy.clearLocalStorage %}

Examples

No Args

Clear all local storage

cy.clearLocalStorage()

Specific Key

Clear local storage with key 'appName'

cy.clearLocalStorage('appName')

Clear all local storage matching /app-/

cy.clearLocalStorage(/app-/)

Rules

Requirements {% helper_icon requirements %}

{% requirements parent cy.clearLocalStorage %}

Assertions {% helper_icon assertions %}

{% assertions none cy.clearLocalStorage %}

Timeouts {% helper_icon timeout %}

{% timeouts none cy.clearLocalStorage %}

Command Log

cy.clearLocalStorage(/prop1|2/).then(function(ls){
  expect(ls.getItem('prop1')).to.be.null
  expect(ls.getItem('prop2')).to.be.null
  expect(ls.getItem('prop3')).to.eq('magenta')
})

The commands above will display in the command log as:

Command log for clearLocalStorage

When clicking on clearLocalStorage within the command log, the console outputs the following:

console.log for clearLocalStorage

See also

  • {% url cy.clearCookies() clearcookies %}