-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6c16d0a
commit 479d124
Showing
6 changed files
with
146 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Cypress | ||
|
||
This project is outfitted with Cypress E2E testing. This is used to cover code where unit tests are difficult to maintain. | ||
|
||
## How to run the tests | ||
|
||
Locally you can run the tests with two commands: | ||
|
||
```sh | ||
# First, install the dependencies | ||
$ npm install | ||
|
||
# Run the normal dev server | ||
$ npm run start | ||
|
||
# Open cypress. It will open a browser window in which you can choose to run integration tests | ||
$ npx cypress open | ||
``` | ||
|
||
## How to add tests | ||
|
||
You can add tests by adding new TypeScript files to the `cypress/e2e` folder. By convention we use | ||
the same name as the `demo` page. So the tests for `demo/while.html` live in | ||
`cypress/e2e/while.cy.ts`. | ||
|
||
Those tests consist of a few parts that are always the same. For example, the test for `while.html` | ||
does the following: | ||
|
||
```typescript | ||
describe('while demo spec', () => { | ||
beforeEach (() => { | ||
// We are testing while.html, so open that page. Cypress will reload this every test | ||
cy.visit('while.html'); | ||
}); | ||
|
||
it('can count to 10', () => { | ||
// Make sure we start at an expected state | ||
cy.get('[data-cy="output"]') | ||
.should('contain', '0') | ||
// Start the counter | ||
cy.get('[data-cy="counter"]') | ||
.click() | ||
// Assert the toast is shown | ||
cy.get('.toastify') | ||
.should('be.visible') | ||
.should('contain', 'counted to 10 done') | ||
// And the counter updated | ||
cy.get('[data-cy="output"]') | ||
.should('contain', '10') | ||
// Test the rest | ||
cy.get('[data-cy="reset"]') | ||
.click() | ||
cy.get('[data-cy="output"]') | ||
.should('contain', '0') | ||
}); | ||
}); | ||
``` | ||
|
||
## Targetting elements | ||
Cypress uses DOM selectors to target elements. Use the `data-cy` attribute to target elements. | ||
|
||
## Cypress versus unit tests | ||
|
||
Because Cypress takes away all timing issues, they are easier to write than normal unit | ||
tests. Normal unit tests can still be useful for API tests (for instance the workings of the XPath | ||
functions, but integration tests should be done in Cypress. | ||
|
||
## CI | ||
|
||
The Cypress tests are executed in Github Actions, on every commit. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
describe('while demo spec', () => { | ||
beforeEach(() => { | ||
cy.visit('ignore.html'); | ||
}); | ||
// @see https://www.thisdot.co/blog/testing-web-components-with-cypress-and-typescript | ||
it('should not ignore all expressions', () => { | ||
cy.get('fx-fore span') | ||
.should('contain', 'Hello') | ||
}); | ||
|
||
it('should ignore expressions under the ignore filter', () => { | ||
cy.get('fx-fore .myElement span') | ||
.first() | ||
.should('contain', '{ignored}'); | ||
cy.get('fx-fore .myElement span') | ||
.last() | ||
.should('contain', '{whatever}'); | ||
}); | ||
|
||
it('should also ignore expressions under the ignore filter that would cause errors', () => { | ||
cy.get('fx-fore .myElement') | ||
.last() | ||
.should('contain', '{}{}{{{}}}'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters