Skip to content

Commit 05743a9

Browse files
authored
Merge branch 'master' into patch-1
2 parents 4e0a336 + 88b1648 commit 05743a9

File tree

83 files changed

+2159
-1498
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+2159
-1498
lines changed

.all-contributorsrc

Lines changed: 390 additions & 1 deletion
Large diffs are not rendered by default.

README.md

Lines changed: 98 additions & 40 deletions
Large diffs are not rendered by default.

docs/angular-testing-library/api.md

Lines changed: 212 additions & 91 deletions
Large diffs are not rendered by default.

docs/angular-testing-library/examples.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ title: Examples
44
sidebar_label: Examples
55
---
66

7+
> Read
8+
> [Good testing practices with 🦔 Angular Testing Library](https://timdeschryver.dev/posts/good-testing-practices-with-angular-testing-library)
9+
> for a guided example
10+
711
counter.component.ts
812

913
```typescript
@@ -31,26 +35,26 @@ export class CounterComponent {
3135
counter.component.spec.ts
3236

3337
```typescript
34-
import { render } from '@testing-library/angular'
35-
import CounterComponent from './counter.component.ts'
38+
import { render, screen, fireEvent } from '@testing-library/angular'
39+
import { CounterComponent } from './counter.component.ts'
3640

3741
describe('Counter', () => {
3842
test('should render counter', async () => {
39-
const { getByText } = await render(CounterComponent, {
43+
await render(CounterComponent, {
4044
componentProperties: { counter: 5 },
4145
})
4246

43-
expect(getByText('Current Count: 5'))
47+
expect(screen.getByText('Current Count: 5'))
4448
})
4549

4650
test('should increment the counter on click', async () => {
47-
const { getByText, click } = await render(CounterComponent, {
51+
await render(CounterComponent, {
4852
componentProperties: { counter: 5 },
4953
})
5054

51-
click(getByText('+'))
55+
fireEvent.click(screen.getByText('+'))
5256

53-
expect(getByText('Current Count: 6'))
57+
expect(screen.getByText('Current Count: 6'))
5458
})
5559
})
5660
```

docs/cypress-testing-library/intro.md

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ Add this line to your project's `cypress/support/commands.js`:
2222
import '@testing-library/cypress/add-commands';
2323
```
2424

25+
You can now use all of `DOM Testing Library`'s `findBy`, `findAllBy`, `queryBy`
26+
and `queryAllBy` commands off the global `cy` object.
27+
[See the `DOM Testing Library` docs for reference](https://testing-library.com/docs/dom-testing-library/api-queries).
28+
29+
> Note: the `get*` queries are not supported because for reasonable Cypress tests you
30+
> need retryability and `find*` queries already support that. `query*` queries are no longer
31+
> necessary since v5 and will be removed in v6. `find*` fully support built-in Cypress
32+
> assertions (removes the only use-case for `query*`).
33+
2534
## With TypeScript
2635

2736
Typings are defined in `@types/testing-library__cypress` at [DefinitelyTyped](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/testing-library__cypress),
@@ -35,40 +44,30 @@ and should be added as follows in `tsconfig.json`:
3544
}
3645
```
3746

38-
You can now use all of `DOM Testing Library`'s `getBy`, `getAllBy`, `queryBy`
39-
and `queryAllBy` commands.
40-
[See `DOM Testing Library` API for reference](dom-testing-library/api-queries.md)
47+
You can find [all Library definitions here](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/testing-library__cypress/index.d.ts).
4148

4249
## Examples
4350

44-
You can find [all library definitions here](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/testing-library__cypress/index.d.ts).
45-
46-
To show some simple examples (from [https://github.com/testing-library/cypress-testing-library/tree/master/cypress/integration](https://github.com/testing-library/cypress-testing-library/tree/master/cypress/integration)):
51+
To show some simple examples (from
52+
[cypress/integration/query.spec.js](https://github.com/testing-library/cypress-testing-library/blob/master/cypress/integration/query.spec.js) or [cypress/integration/find.spec.js](https://github.com/testing-library/cypress-testing-library/blob/master/cypress/integration/find.spec.js)):
4753

4854
```javascript
49-
cy.findAllByText(/^Button Text \d$/)
50-
.should('have.length', 2)
51-
.click({ multiple: true })
52-
.should('contain', 'Button Clicked')
53-
cy.queryByText('Button Text 1')
54-
.click()
55-
.should('contain', 'Button Clicked')
56-
cy.queryByText('Non-existing Button Text', { timeout: 100 }).should('not.exist')
57-
cy.queryByLabelText('Label 1')
58-
.click()
59-
.type('Hello Input Labelled By Id')
60-
cy.get('#nested').within(() => {
61-
cy.queryByText('Button Text 2').click()
62-
})
63-
cy.get('#nested').then(subject => {
64-
cy.queryByText(/^Button Text/, { container: subject }).click()
55+
cy.findByRole('button', {name: /Jackie Chan/i}).click()
56+
cy.findByRole('button', {name: /Button Text/i}).should('exist')
57+
cy.findByRole('button', {name: /Non-existing Button Text/i}).should('not.exist')
58+
cy.findByLabelText(/Label text/i, {timeout: 7000}).should('exist')
59+
60+
// findAllByText _inside_ a form element
61+
cy.get('form').findByText('button', {name: /Button Text/i}).should('exist')
62+
cy.findByRole('dialog').within(() => {
63+
cy.findByRole('button', {name: /confirm/i})
6564
})
6665
```
6766

6867
`Cypress Testing Library` supports both jQuery elements and DOM nodes. This is
6968
necessary because Cypress uses jQuery elements, while `DOM Testing Library`
7069
expects DOM nodes. When you pass a jQuery element as `container`, it will get
7170
the first DOM node from the collection and use that as the `container` parameter
72-
for the DOM Testing Library functions.
71+
for the `DOM Testing Library` functions.
7372

7473
[gh]: https://github.com/testing-library/cypress-testing-library

0 commit comments

Comments
 (0)