mirror of
https://github.com/cypress-io/cypress.git
synced 2026-04-30 12:01:06 -05:00
Add typedefs for Cypress.LocalStorage.clear (#4168)
* add typedefs for LocalStorage.clear * clean up unused arguments * appease the linter
This commit is contained in:
committed by
Jennifer Shehane
parent
bf1a942944
commit
1b1c2f24bd
Vendored
+19
@@ -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
|
||||
|
||||
@@ -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])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user