Skip to content

Commit d344f14

Browse files
authored
Merge pull request #9 from javierbrea/improve-docs
Improve docs
2 parents f7cc9a8 + 3452cd0 commit d344f14

File tree

1 file changed

+38
-6
lines changed

1 file changed

+38
-6
lines changed

README.md

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,28 +36,60 @@ import "cypress-localstorage-commands"
3636

3737
You can now use all next commands:
3838

39+
### Commands
40+
41+
Save current localStorage values into an internal "snapshot":
42+
43+
```js
44+
cy.saveLocalStorage();
45+
```
46+
47+
Restore localStorage to previously "snapshot" saved values:
48+
3949
```js
40-
cy.saveLocalStorage() // Save current localStorage values into an internal "snapshot"
50+
cy.restoreLocalStorage();
4151
```
4252

53+
Clear localStorage "snapshot" values:
54+
4355
```js
44-
cy.restoreLocalStorage() // Restore localStorage to previously "snapshot" saved values
56+
cy.clearLocalStorageSnapshot();
4557
```
4658

59+
Get localStorage item. Equivalent to `localStorage.getItem` in browser:
60+
4761
```js
48-
cy.clearLocalStorageSnapshot() // Clear localStorage "snapshot" values
62+
cy.getLocalStorage("item");
4963
```
5064

65+
Set localStorage item. Equivalent to `localStorage.setItem` in browser:
66+
5167
```js
52-
cy.getLocalStorage("item") // Get localStorage item
68+
cy.setLocalStorage("item", "value");
5369
```
5470

71+
Remove localStorage item. Equivalent to `localStorage.removeItem` in browser:
72+
5573
```js
56-
cy.setLocalStorage("item", "value") // Set localStorage item
74+
cy.removeLocalStorage("item");
5775
```
5876

77+
### Preserving local storage between tests
78+
79+
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:
80+
5981
```js
60-
cy.removeLocalStorage("item") // Remove localStorage item
82+
it("should hide privacy policy message on click accept cookies button", () => {
83+
cy.get("#accept-cookies").click();
84+
cy.get("#privacy-policy").should("not.be.visible");
85+
cy.saveLocalStorage();
86+
});
87+
88+
it("should not show privacy policy message after reloading page", () => {
89+
cy.restoreLocalStorage();
90+
cy.reload();
91+
cy.get("#privacy-policy").should("not.be.visible");
92+
});
6193
```
6294

6395
## Contributing

0 commit comments

Comments
 (0)