Add typedefs for Cypress.LocalStorage.clear (#4168)

* add typedefs for LocalStorage.clear

* clean up unused arguments

* appease the linter
This commit is contained in:
Zach Bloomquist
2019-05-13 06:28:20 -04:00
committed by Jennifer Shehane
parent bf1a942944
commit 1b1c2f24bd
3 changed files with 28 additions and 3 deletions
+19
View File
@@ -62,6 +62,20 @@ declare namespace Cypress {
isHeadless: boolean
}
interface LocalStorage {
/**
* Called internally to clear `localStorage` in two situations.
*
* 1. Before every test, this is called with no argument to clear all keys.
* 2. On `cy.clearLocalStorage(keys)` this is called with `keys` as an argument.
*
* You should not call this method directly to clear `localStorage`; instead, use `cy.clearLocalStorage(key)`.
*
* @see https://on.cypress.io/clearlocalstorage
*/
clear: (keys?: string[]) => void
}
/**
* Several libraries are bundled with Cypress by default.
*
@@ -171,6 +185,11 @@ declare namespace Cypress {
*/
browser: Browser
/**
* Internal class for LocalStorage management.
*/
LocalStorage: LocalStorage
/**
* Returns all configuration objects.
* @see https://on.cypress.io/config
+6
View File
@@ -78,6 +78,12 @@ namespace CypressLogsTest {
log.get('$el') // $ExpectType JQuery<HTMLElement>
}
namespace CypressLocalStorageTest {
Cypress.LocalStorage.clear = function(keys) {
keys // $ExpectType string[] | undefined
}
}
cy.wrap({ foo: [1, 2, 3] })
.its('foo')
.each((s: number) => {
@@ -8,15 +8,15 @@ $LocalStorage = {
localStorage: null
remoteStorage: null
clear: (keys, local, remote) ->
clear: (keys) ->
# TODO: update this to utils.throwErrByPath() if uncommented
# throw new Error("Cypress.LocalStorage is missing local and remote storage references!") if not @localStorage or not @remoteStorage
## make sure we always have an array here with all falsy values removed
keys = _.compact([].concat(keys))
local ?= @localStorage
remote ?= @remoteStorage
local = @localStorage
remote = @remoteStorage
storages = _.compact([local, remote])