From 0182dcda064222b452ac811951023ccf101e430a Mon Sep 17 00:00:00 2001 From: Mark Date: Sun, 3 Dec 2023 15:53:07 -0500 Subject: [PATCH] feat(assertions): add "Then I see session storage item" --- src/actions/session-storage.ts | 6 ++---- src/assertions/index.ts | 1 + src/assertions/session-storage.ts | 24 ++++++++++++++++++++++++ 3 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 src/assertions/session-storage.ts diff --git a/src/actions/session-storage.ts b/src/actions/session-storage.ts index beea2b639..b4b89f71a 100644 --- a/src/actions/session-storage.ts +++ b/src/actions/session-storage.ts @@ -7,7 +7,7 @@ import { When } from '@badeball/cypress-cucumber-preprocessor'; * When I clear session storage * ``` * - * Clears [`sessionStorage`](https://developer.mozilla.org/docs/Web/API/Window/sessionStorage) data for all origins with which the test has interacted. + * Clear [`sessionStorage`](https://developer.mozilla.org/docs/Web/API/Window/sessionStorage) data for all origins with which the test has interacted. * * @example * @@ -20,9 +20,7 @@ import { When } from '@badeball/cypress-cucumber-preprocessor'; * @remarks * * - * Cypress automatically clears all session 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 sessionStorage inside a single test or test isolation is disabled. + * Cypress automatically clears all session 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 sessionStorage inside a single test or test isolation is disabled. */ export function When_I_clear_session_storage() { cy.clearAllSessionStorage(); diff --git a/src/assertions/index.ts b/src/assertions/index.ts index 363205da4..d5bc07a4a 100644 --- a/src/assertions/index.ts +++ b/src/assertions/index.ts @@ -10,6 +10,7 @@ export * from './link'; export * from './local-storage'; export * from './option'; export * from './response'; +export * from './session-storage'; export * from './text'; export * from './url'; export * from './value'; diff --git a/src/assertions/session-storage.ts b/src/assertions/session-storage.ts new file mode 100644 index 000000000..ae67fcff1 --- /dev/null +++ b/src/assertions/session-storage.ts @@ -0,0 +1,24 @@ +import { Then } from '@badeball/cypress-cucumber-preprocessor'; + +/** + * Then I see session storage item: + * + * ```gherkin + * Then I see session storage item {string} + * ``` + * + * Assert session storage item **_exists_**. + * + * @example + * + * ```gherkin + * Then I see session storage item "key" + * ``` + */ +export function Then_I_see_session_storage_item(key: string) { + cy.wrap({}).should(() => { + expect(sessionStorage.getItem(key)).to.exist; + }); +} + +Then('I see session storage item {string}', Then_I_see_session_storage_item);