nx/docs/tutorial/02-add-e2e-test.md
2019-02-28 13:53:43 -05:00

41 lines
1.1 KiB
Markdown

# Step 2: Add E2E Test
By default, Nx uses Cypress to run E2E tests.
**Open `apps/todos-e2e/src/support/app.po.ts`.** It's a page object file that contains helpers for querying the page.
**Add the following two helpers:**
```typescript
export const getTodos = () => cy.get('li.todo');
export const getAddTodoButton = () => cy.get('button#add-todo');
```
**Next, update `apps/todos-e2e/src/integration/app.spec.ts`.**
```typescript
import { getAddTodoButton, getTodos } from '../support/app.po';
describe('TodoApps', () => {
beforeEach(() => cy.visit('/'));
it('should display todos', () => {
getTodos().should(t => expect(t.length).equal(2));
getAddTodoButton().click();
getTodos().should(t => expect(t.length).equal(3));
});
});
```
This is, obviously, not a great example of an E2E test, but the purposes of this tutorial it will do.
**If you haven't done it already, stop the `ng serve` command and run `ng e2e todos-e2e --watch`.**
!!!!!
What assertion fails?
!!!!!
Expect 0 to equal 2
Nothing fails. Everything works.
Cannot find any elements matching 'li.todo'
Cannot find any elements matching 'button#add-todo'