Skip to content

Commit fd8cfd2

Browse files
authored
Merge pull request #90 from javierbrea/typescript-support
Typescript support
2 parents d188a70 + 84027b8 commit fd8cfd2

25 files changed

+3612
-299
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1111
### Removed
1212
### BREAKING CHANGES
1313

14+
## [1.2.0] - 2020-05-31
15+
16+
### Added
17+
- feat(TypeScript): Add TypeScript support
18+
1419
## [1.1.10] - 2020-05-16
1520

1621
### Added

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,26 @@ describe("localStorage cookies-accepted item", () => {
150150
});
151151
```
152152

153+
## Usage with TypeScript
154+
155+
For those writing [TypesScript tests in Cypress][cypress-typescript], this package includes TypeScript declarations.
156+
157+
Add "cypress-localstorage-commands" to the `types` property of the `tsconfig.json` file:
158+
159+
```json
160+
{
161+
"compilerOptions": {
162+
"types": ["cypress", "cypress-localstorage-commands"]
163+
}
164+
}
165+
```
166+
167+
Or reference the package in the files using it:
168+
169+
```typescript
170+
/// <reference types="cypress-localstorage-commands" />
171+
```
172+
153173
## Contributing
154174

155175
Contributors are welcome.
@@ -175,3 +195,5 @@ MIT, see [LICENSE](./LICENSE) for details.
175195
[quality-gate-url]: https://sonarcloud.io/dashboard?id=cypress-localstorage-commands
176196
[release-image]: https://img.shields.io/github/release-date/javierbrea/cypress-localstorage-commands.svg
177197
[release-url]: https://github.com/javierbrea/cypress-localstorage-commands/releases
198+
199+
[cypress-typescript]: https://docs.cypress.io/guides/tooling/typescript-support.html

index.d.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/// <reference types="cypress" />
2+
3+
declare namespace Cypress {
4+
interface Chainable {
5+
/**
6+
* Command to save current localStorage values into an internal "snapshot"
7+
* @example cy.saveLocalStorage()
8+
*/
9+
saveLocalStorage(): Chainable<Element>
10+
11+
/**
12+
* Command to restore localStorage to previously "snapshot" saved values
13+
* @example cy.restoreLocalStorage()
14+
*/
15+
restoreLocalStorage(): Chainable<Element>
16+
17+
/**
18+
* Command to clear localStorage "snapshot" values
19+
* @example cy.clearLocalStorageSnapshot()
20+
*/
21+
clearLocalStorageSnapshot(): Chainable<Element>
22+
23+
/**
24+
* Command to get localStorage item value
25+
* @param {string} itemKeyName - localStorage item to get
26+
* @example cy.getLocalStorage("cookies-accepted")
27+
*/
28+
getLocalStorage(itemKeyName: string): Chainable<Element>
29+
30+
/**
31+
* Command to set localStorage item value
32+
* @param {string} itemKeyName - localStorage item to set
33+
* @param {string} value - value to be set
34+
* @example cy.setLocalStorage("cookies-accepted", "true")
35+
*/
36+
setLocalStorage(itemKeyName: string, value: string): Chainable<Element>
37+
38+
/**
39+
* Command to remove localStorage item
40+
* @param {string} itemKeyName - localStorage item to remove
41+
* @example cy.removeLocalStorage("cookies-accepted")
42+
*/
43+
removeLocalStorage(itemKeyName: string): Chainable<Element>
44+
}
45+
}

0 commit comments

Comments
 (0)