Socket
Socket
Sign inDemoInstall

cypress-localstorage-commands

Package Overview
Dependencies
174
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 1.1.0

10

CHANGELOG.md

@@ -14,2 +14,12 @@ # Change Log

## [1.1.0] - 2019-10-27
### Added
- Add getLocalStorage command
- Add setLocalStorage command
- Add removeLocalStorage command
- Add acceptance tests
### Changed
- Improve documentation
## [1.0.0] - 2019-10-26

@@ -16,0 +26,0 @@ ### Added

10

package.json
{
"name": "cypress-localstorage-commands",
"version": "1.0.0",
"version": "1.1.0",
"description": "Extends Cypress' cy commands with localStorage methods. Allows preserving localStorage between tests",

@@ -25,3 +25,3 @@ "keywords": [

"coveralls": "cat ./coverage/lcov.info | coveralls",
"lint": "eslint src test",
"lint": "eslint src test test-acceptance/app/src test-acceptance/app/cypress",
"lint-staged": "lint-staged",

@@ -32,2 +32,3 @@ "test": "jest"

"devDependencies": {
"babel-eslint": "^10.0.3",
"coveralls": "^3.0.7",

@@ -37,2 +38,3 @@ "eslint": "6.6.0",

"eslint-plugin-prettier": "^3.1.1",
"eslint-plugin-react": "^7.16.0",
"husky": "^3.0.9",

@@ -49,3 +51,5 @@ "jest": "^24.9.0",

"src/**/*.js": "eslint",
"test/**/*.js": "eslint"
"test/**/*.js": "eslint",
"test-acceptance/app/src/**/*.js": "eslint",
"test-acceptance/app/cypress/**/*.js": "eslint"
},

@@ -52,0 +56,0 @@ "husky": {

@@ -34,3 +34,3 @@ [![Build status][travisci-image]][travisci-url] [![Coverage Status][coveralls-image]][coveralls-url] [![Quality Gate][quality-gate-image]][quality-gate-url]

```js
import 'cypress-localstorage-commands'
import "cypress-localstorage-commands"
```

@@ -40,14 +40,58 @@

### Commands
Save current localStorage values into an internal "snapshot":
```js
cy.saveLocalStorage() // Save current localStorage values into an internal "snapshot"
cy.saveLocalStorage();
```
Restore localStorage to previously "snapshot" saved values:
```js
cy.restoreLocalStorage() // Restore localStorage to previously "snapshot" saved values
cy.restoreLocalStorage();
```
Clear localStorage "snapshot" values:
```js
cy.clearLocalStorageSnapshot() // Clear localStorage "snapshot" values
cy.clearLocalStorageSnapshot();
```
Get localStorage item. Equivalent to `localStorage.getItem` in browser:
```js
cy.getLocalStorage("item");
```
Set localStorage item. Equivalent to `localStorage.setItem` in browser:
```js
cy.setLocalStorage("item", "value");
```
Remove localStorage item. Equivalent to `localStorage.removeItem` in browser:
```js
cy.removeLocalStorage("item");
```
### Preserving local storage between tests
Use `saveLocalStorage` to save a snapshot of current `localStorage` at the end of one test, and use the `restoreLocalStorage` command to restore it at the beginning of another one:
```js
it("should hide privacy policy message on click accept cookies button", () => {
cy.get("#accept-cookies").click();
cy.get("#privacy-policy").should("not.be.visible");
cy.saveLocalStorage();
});
it("should not show privacy policy message after reloading page", () => {
cy.restoreLocalStorage();
cy.reload();
cy.get("#privacy-policy").should("not.be.visible");
});
```
## Contributing

@@ -54,0 +98,0 @@

class LocalStorage {
static get cypressCommands() {
return ["clearLocalStorageSnapshot", "saveLocalStorage", "restoreLocalStorage"];
return [
"clearLocalStorageSnapshot",
"saveLocalStorage",
"restoreLocalStorage",
"setLocalStorage",
"getLocalStorage",
"removeLocalStorage"
];
}

@@ -28,4 +35,16 @@

}
getLocalStorage(key) {
return this._localStorage.getItem(key);
}
setLocalStorage(key, value) {
return this._localStorage.setItem(key, value);
}
removeLocalStorage(key) {
return this._localStorage.removeItem(key);
}
}
module.exports = LocalStorage;
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc