From df2407b58cf982fab4fa9242cc015ba5da3bd2e8 Mon Sep 17 00:00:00 2001 From: Mark Date: Sat, 14 Jan 2023 16:37:06 -0500 Subject: [PATCH] feat(actions): add "When I clear local storage" --- src/actions/index.ts | 1 + src/actions/local-storage.ts | 40 ++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 src/actions/local-storage.ts diff --git a/src/actions/index.ts b/src/actions/index.ts index 0e0ca9af0..e85116355 100644 --- a/src/actions/index.ts +++ b/src/actions/index.ts @@ -5,6 +5,7 @@ export * from './cookie'; export * from './debug'; export * from './double-click'; export * from './go'; +export * from './local-storage'; export * from './log'; export * from './pause'; export * from './reload'; diff --git a/src/actions/local-storage.ts b/src/actions/local-storage.ts new file mode 100644 index 000000000..a87cc48bc --- /dev/null +++ b/src/actions/local-storage.ts @@ -0,0 +1,40 @@ +import { When } from '@badeball/cypress-cucumber-preprocessor'; + +/* eslint-disable tsdoc/syntax */ +/** + * When I clear local storage: + * + * ```gherkin + * When I clear local storage + * When I clear local storage {string} + * ``` + * + * @example + * + * Clear all localStorage: + * + * ```gherkin + * When I clear local storage + * ``` + * + * Clear localStorage with the key `appName`: + * + * ```gherkin + * When I clear local storage "appName" + * ``` + * + * @remarks + * + * Clears [`localStorage`](https://developer.mozilla.org/docs/Web/API/Window/localStorage) data for current domain and subdomain. + * + * > Cypress automatically clears all local storage before each test to prevent state from being shared across tests when [test isolation](https://docs.cypress.io/guides/core-concepts/writing-and-organizing-tests#Test-Isolation) is enabled. + * > + * > You shouldn't need to use this command unless you're using it to clear localStorage inside a single test or test isolation is disabled. + */ +/* eslint-enable tsdoc/syntax */ +export function When_I_clear_local_storage(key?: string) { + cy.clearLocalStorage(key); +} + +When('I clear local storage', When_I_clear_local_storage); +When('I clear local storage {string}', When_I_clear_local_storage);