Skip to content

Commit

Permalink
feat(assertions): add "Then I see session storage item"
Browse files Browse the repository at this point in the history
  • Loading branch information
remarkablemark committed Dec 3, 2023
1 parent 18c95e6 commit 0182dcd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/actions/session-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/assertions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
24 changes: 24 additions & 0 deletions src/assertions/session-storage.ts
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit 0182dcd

Please sign in to comment.