Skip to content

Commit 12cdc91

Browse files
authored
Update cypress.md
1 parent 8565d90 commit 12cdc91

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

docs/testing/cypress.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ cy.tick(waitMilliseconds);
257257
cy.get('#logoutNotification').should('be.visible');
258258
```
259259

260-
## Tip: Smart delays
260+
## Tip: Smart delays and retries
261261
Cypress will automatically wait (and retry) for many async things e.g.
262262
```
263263
// If there is no request against the `foo` alias cypress will wait for 4 seconds automatically
@@ -267,6 +267,24 @@ cy.get('#foo')
267267
```
268268
This keeps you from having to constantly add arbitrary timeout (and retry) logic in your test code flow.
269269

270+
271+
## Tip: Unit testing applicaiton code
272+
You can also use cypress to unit test your application code in isolation e.g.
273+
274+
```js
275+
import { once } from '../../../src/app/utils';
276+
277+
// Later
278+
it('should only call function once', () => {
279+
let called = 0;
280+
const callMe = once(()=>called++);
281+
callMe();
282+
callMe();
283+
expect(called).to.equal(1);
284+
});
285+
```
286+
287+
270288
## Resources
271289
* Website: https://www.cypress.io/
272290
* Write your first cypress test (gives a nice tour of the cypress IDE) : https://docs.cypress.io/guides/getting-started/writing-your-first-test.html

0 commit comments

Comments
 (0)