Skip to content

Commit e2783d1

Browse files
authored
Merge branch 'main' into pr/add-reactStrictMode-option
2 parents 48f3b1f + 50ad2d2 commit e2783d1

Some content is hidden

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

50 files changed

+760
-523
lines changed

Diff for: .all-contributorsrc

+63
Original file line numberDiff line numberDiff line change
@@ -2555,6 +2555,69 @@
25552555
"contributions": [
25562556
"doc"
25572557
]
2558+
},
2559+
{
2560+
"login": "JoyelJohny",
2561+
"name": "Joyel Johny",
2562+
"avatar_url": "https://avatars.githubusercontent.com/u/81413791?v=4",
2563+
"profile": "https://github.com/JoyelJohny",
2564+
"contributions": [
2565+
"code"
2566+
]
2567+
},
2568+
{
2569+
"login": "bsheps",
2570+
"name": "bsheps",
2571+
"avatar_url": "https://avatars.githubusercontent.com/u/35780702?v=4",
2572+
"profile": "https://github.com/bsheps",
2573+
"contributions": [
2574+
"doc"
2575+
]
2576+
},
2577+
{
2578+
"login": "kyle-n",
2579+
"name": "Kyle Nazario",
2580+
"avatar_url": "https://avatars.githubusercontent.com/u/13384477?v=4",
2581+
"profile": "http://www.kylenazario.com",
2582+
"contributions": [
2583+
"doc"
2584+
]
2585+
},
2586+
{
2587+
"login": "thefalked",
2588+
"name": "Giuliano Crivelli",
2589+
"avatar_url": "https://avatars.githubusercontent.com/u/28029756?v=4",
2590+
"profile": "https://github.com/thefalked",
2591+
"contributions": [
2592+
"doc"
2593+
]
2594+
},
2595+
{
2596+
"login": "mroforolhc",
2597+
"name": "mrkv",
2598+
"avatar_url": "https://avatars.githubusercontent.com/u/26799398?v=4",
2599+
"profile": "https://t.me/markov_ka",
2600+
"contributions": [
2601+
"doc"
2602+
]
2603+
},
2604+
{
2605+
"login": "smk267",
2606+
"name": "smk267",
2607+
"avatar_url": "https://avatars.githubusercontent.com/u/88115182?v=4",
2608+
"profile": "https://github.com/smk267",
2609+
"contributions": [
2610+
"infra"
2611+
]
2612+
},
2613+
{
2614+
"login": "agentdylan",
2615+
"name": "Dylan Gordon",
2616+
"avatar_url": "https://avatars.githubusercontent.com/u/3656794?v=4",
2617+
"profile": "https://www.dylangordon.co.nz/",
2618+
"contributions": [
2619+
"doc"
2620+
]
25582621
}
25592622
],
25602623
"contributorsPerLine": 7,

Diff for: README.md

+9
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,15 @@ Thanks goes to these wonderful people
498498
<tr>
499499
<td align="center" valign="top" width="14.28%"><a href="https://github.com/andnorda"><img src="https://avatars.githubusercontent.com/u/1894119?v=4?s=100" width="100px;" alt="Andreas Nordahl"/><br /><sub><b>Andreas Nordahl</b></sub></a><br /><a href="https://github.com/testing-library/testing-library-docs/commits?author=andnorda" title="Documentation">📖</a></td>
500500
<td align="center" valign="top" width="14.28%"><a href="https://neaumusic.github.io"><img src="https://avatars.githubusercontent.com/u/3423750?v=4?s=100" width="100px;" alt="neaumusic"/><br /><sub><b>neaumusic</b></sub></a><br /><a href="https://github.com/testing-library/testing-library-docs/commits?author=neaumusic" title="Documentation">📖</a></td>
501+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/JoyelJohny"><img src="https://avatars.githubusercontent.com/u/81413791?v=4?s=100" width="100px;" alt="Joyel Johny"/><br /><sub><b>Joyel Johny</b></sub></a><br /><a href="https://github.com/testing-library/testing-library-docs/commits?author=JoyelJohny" title="Code">💻</a></td>
502+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/bsheps"><img src="https://avatars.githubusercontent.com/u/35780702?v=4?s=100" width="100px;" alt="bsheps"/><br /><sub><b>bsheps</b></sub></a><br /><a href="https://github.com/testing-library/testing-library-docs/commits?author=bsheps" title="Documentation">📖</a></td>
503+
<td align="center" valign="top" width="14.28%"><a href="http://www.kylenazario.com"><img src="https://avatars.githubusercontent.com/u/13384477?v=4?s=100" width="100px;" alt="Kyle Nazario"/><br /><sub><b>Kyle Nazario</b></sub></a><br /><a href="https://github.com/testing-library/testing-library-docs/commits?author=kyle-n" title="Documentation">📖</a></td>
504+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/thefalked"><img src="https://avatars.githubusercontent.com/u/28029756?v=4?s=100" width="100px;" alt="Giuliano Crivelli"/><br /><sub><b>Giuliano Crivelli</b></sub></a><br /><a href="https://github.com/testing-library/testing-library-docs/commits?author=thefalked" title="Documentation">📖</a></td>
505+
<td align="center" valign="top" width="14.28%"><a href="https://t.me/markov_ka"><img src="https://avatars.githubusercontent.com/u/26799398?v=4?s=100" width="100px;" alt="mrkv"/><br /><sub><b>mrkv</b></sub></a><br /><a href="https://github.com/testing-library/testing-library-docs/commits?author=mroforolhc" title="Documentation">📖</a></td>
506+
</tr>
507+
<tr>
508+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/smk267"><img src="https://avatars.githubusercontent.com/u/88115182?v=4?s=100" width="100px;" alt="smk267"/><br /><sub><b>smk267</b></sub></a><br /><a href="#infra-smk267" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td>
509+
<td align="center" valign="top" width="14.28%"><a href="https://www.dylangordon.co.nz/"><img src="https://avatars.githubusercontent.com/u/3656794?v=4?s=100" width="100px;" alt="Dylan Gordon"/><br /><sub><b>Dylan Gordon</b></sub></a><br /><a href="https://github.com/testing-library/testing-library-docs/commits?author=agentdylan" title="Documentation">📖</a></td>
501510
</tr>
502511
</tbody>
503512
</table>

Diff for: docs/angular-testing-library/api.mdx

+77-3
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,42 @@ await render(AppComponent, {
150150
})
151151
```
152152

153+
### `deferBlockBehavior`
154+
155+
Set the defer blocks behavior.
156+
157+
For more info see the
158+
[Angular docs](https://angular.io/api/core/testing/DeferBlockBehavior)
159+
160+
**default** : `undefined` (uses the Angular default, which is
161+
`DeferBlockBehavior.Manual`)
162+
163+
**example**:
164+
165+
```typescript
166+
await render(AppComponent, {
167+
deferBlockBehavior: DeferBlockBehavior.Playthrough,
168+
})
169+
```
170+
171+
### `deferBlockStates`
172+
173+
Set the initial state of a deferrable blocks in a component.
174+
175+
For more info see the
176+
[Angular docs](https://angular.io/api/core/testing/DeferBlockState)
177+
178+
**default** : `undefined` (uses the Angular default, which is
179+
`DeferBlockState.Placeholder`)
180+
181+
**example**:
182+
183+
```typescript
184+
await render(FixtureComponent, {
185+
deferBlockStates: DeferBlockState.Loading,
186+
})
187+
```
188+
153189
### `componentProviders`
154190

155191
A collection of providers needed to render the component via Dependency
@@ -395,20 +431,39 @@ properties that are not defined are cleared.
395431

396432
```typescript
397433
const {rerender} = await render(Counter, {
398-
componentProperties: {count: 4, name: 'Sarah'},
434+
componentInputs: {count: 4, name: 'Sarah'},
399435
})
400436
401437
expect(screen.getByTestId('count-value').textContent).toBe('4')
402438
expect(screen.getByTestId('name-value').textContent).toBe('Sarah')
403439
404-
await rerender({componentProperties: {count: 7}})
440+
await rerender({componentInputs: {count: 7}})
405441
406-
// count updated to 7
442+
// count is updated to 7
407443
expect(screen.getByTestId('count-value').textContent).toBe('7')
408444
// name is undefined because it's not provided in rerender
409445
expect(screen.getByTestId('name-value').textContent).toBeUndefined()
410446
```
411447

448+
Using `partialUpdate`, only the newly provided properties will be updated. Other
449+
input properties that aren't provided won't be cleared.
450+
451+
```typescript
452+
const {rerender} = await render(Counter, {
453+
componentInputs: {count: 4, name: 'Sarah'},
454+
})
455+
456+
expect(screen.getByTestId('count-value').textContent).toBe('4')
457+
expect(screen.getByTestId('name-value').textContent).toBe('Sarah')
458+
459+
await rerender({componentInputs: {count: 7}, partialUpdate: true})
460+
461+
// count is updated to 7
462+
expect(screen.getByTestId('count-value').textContent).toBe('7')
463+
// name is still rendered as "Sarah" because of the partial update
464+
expect(screen.getByTestId('name-value').textContent).toBe('Sarah')
465+
```
466+
412467
### `detectChanges`
413468

414469
Trigger a change detection cycle for the component.
@@ -473,3 +528,22 @@ screen.getByRole('heading', {
473528
})
474529
queryByLabelText(/First name/i')
475530
```
531+
532+
### `renderDeferBlock`
533+
534+
To test [Deferrable views](https://angular.dev/guide/defer#defer), you can make
535+
use of `renderDeferBlock`. `renderDeferBlock` will set the desired defer state
536+
for a specific deferrable block. The default value of a deferrable view is
537+
`Placeholder`, but you can also set the initial state while rendering the
538+
component.
539+
540+
```typescript
541+
const {renderDeferBlock} = await render(FixtureComponent, {
542+
deferBlockStates: DeferBlockState.Loading,
543+
})
544+
545+
expect(screen.getByText(/loading/i)).toBeInTheDocument()
546+
547+
await renderDeferBlock(DeferBlockState.Complete)
548+
expect(screen.getByText(/completed/i)).toBeInTheDocument()
549+
```

Diff for: docs/angular-testing-library/examples.mdx

+14-9
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,13 @@ describe('Counter', () => {
5757

5858
## With Standalone Components
5959

60-
Angular Testing Library can also test your standalone components.
61-
In fact, it even becomes easier because you don't have to set up the whole Angular TestBed.
62-
This was previously only [possible when you used Single Component Angular Modules (SCAMs)](https://timdeschryver.dev/blog/single-component-angular-modules-and-component-tests-go-hand-in-hand).
60+
Angular Testing Library can also test your standalone components. In fact, it
61+
even becomes easier because you don't have to set up the whole Angular TestBed.
62+
This was previously only
63+
[possible when you used Single Component Angular Modules (SCAMs)](https://timdeschryver.dev/blog/single-component-angular-modules-and-component-tests-go-hand-in-hand).
6364

64-
Let's migrate the counter component to a standalone component, and let's take a look at how this affects the test.
65+
Let's migrate the counter component to a standalone component, and let's take a
66+
look at how this affects the test.
6567

6668
```ts title="counter.component.ts"
6769
@Component({
@@ -86,8 +88,8 @@ export class CounterComponent {
8688
}
8789
```
8890

89-
Just as you would've expected, this doesn't affect the test cases.
90-
Writing tests for standalone components remains the same as for "regular" components.
91+
Just as you would've expected, this doesn't affect the test cases. Writing tests
92+
for standalone components remains the same as for "regular" components.
9193

9294
```ts title="counter.component.spec.ts"
9395
import {render, screen, fireEvent} from '@testing-library/angular'
@@ -114,7 +116,8 @@ describe('Counter', () => {
114116
})
115117
```
116118

117-
To override an import of a standalone component for your component test, you can use the [`componentImports` property](api.mdx#componentImports).
119+
To override an import of a standalone component for your component test, you can
120+
use the [`componentImports` property](api.mdx#componentImports).
118121

119122
## More examples
120123

@@ -125,7 +128,9 @@ These examples include:
125128
- `@Input` and `@Output` properties
126129
- Forms
127130
- Integration with services
128-
- And [more](https://github.com/testing-library/angular-testing-library/tree/master/apps/example-app/src/app/examples)
131+
- And
132+
[more](https://github.com/testing-library/angular-testing-library/tree/master/apps/example-app/src/app/examples)
129133

130134
If you're looking for an example that isn't on the list, please feel free to
131-
create a [new issue](https://github.com/testing-library/angular-testing-library/issues/new).
135+
create a
136+
[new issue](https://github.com/testing-library/angular-testing-library/issues/new).

Diff for: docs/angular-testing-library/faq.mdx

+3-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ As you write your tests, keep in mind:
3131

3232
In general, you should avoid mocking out components (see
3333
[the Guiding Principles section](guiding-principles.mdx)). However, if you need
34-
to, then try to use [ng-mocks](https://ng-mocks.sudo.eu/) and its [`MockBuilder`](https://ng-mocks.sudo.eu/extra/with-3rd-party#testing-libraryangular-and-mockbuilder).
34+
to, then try to use [ng-mocks](https://ng-mocks.sudo.eu/) and its
35+
[`MockBuilder`](https://ng-mocks.sudo.eu/extra/with-3rd-party#testing-libraryangular-and-mockbuilder).
3536

3637
```typescript
3738
import {Component, NgModule} from '@angular/core'
@@ -58,7 +59,7 @@ export class AppModule {}
5859
describe('ParentComponent', () => {
5960
it('should not render ChildComponent when shallow rendering', async () => {
6061
// all imports, declarations and exports of AppModule will be mocked.
61-
const dependencies = MockBuilder(ParentComponent, AppModule).build();
62+
const dependencies = MockBuilder(ParentComponent, AppModule).build()
6263

6364
await render(ParentComponent, dependencies)
6465

Diff for: docs/angular-testing-library/version-compatibility.mdx

+7-6
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ id: version-compatibility
33
title: Version compatibility
44
---
55

6-
An overview of the compatibility between different versions of Angular Testing Library and Angular.
6+
An overview of the compatibility between different versions of Angular Testing
7+
Library and Angular.
78

89
| Angular | Angular Testing Library |
910
| ------- | ----------------------- |
10-
| 16.x | 13.x \|\| 14.x |
11-
| >= 15.1 | 13.x \|\| 14.x |
12-
| < 15.1 | 11.x \|\| 12.x |
13-
| 14.x | 11.x \|\| 12.x |
14-
11+
| 17.x | 15.x, 14.x, 13.x |
12+
| 16.x | 14.x, 13.x |
13+
| >= 15.1 | 14.x, 13.x |
14+
| < 15.1 | 12.x, 11.x |
15+
| 14.x | 12.x, 11.x |

Diff for: docs/bs-react-testing-library/intro.mdx

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ Bindings for several testing libraries have been ported to [ReasonML][re].
1515

1616
```bash npm2yarn
1717
npm install --save-dev bs-dom-testing-library
18+
```
19+
20+
```bash npm2yarn
1821
npm install --save-dev bs-react-testing-library
1922
```
2023

Diff for: docs/cypress-testing-library/intro.mdx

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ 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.
25+
You can now use some of `DOM Testing Library`'s `findBy`, and `findAllBy` commands off the global `cy` object.
2726
[See the `About queries` docs for reference](/docs/queries/about).
2827

2928
> Note: the `get*` queries are not supported because for reasonable Cypress

Diff for: docs/dom-testing-library/api-custom-queries.mdx

-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ id: api-custom-queries
33
title: Custom Queries
44
---
55

6-
import Tabs from '@theme/Tabs'
7-
import TabItem from '@theme/TabItem'
8-
96
`DOM Testing Library` exposes many of the helper functions that are used to
107
implement the default queries. You can use the helpers to build custom queries.
118
For example, the code below shows a way to override the default `testId` queries

Diff for: docs/dom-testing-library/api-debugging.mdx

+10-10
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ value is `7000`. You will see `...` in the console, when the DOM content is
3232
stripped off, because of the length you have set or due to default size limit.
3333
Here's how you might increase this limit when running tests:
3434

35-
```
35+
```bash npm2yarn
3636
DEBUG_PRINT_LIMIT=10000 npm test
3737
```
3838

@@ -42,11 +42,11 @@ you'd like a solution that works for both, see
4242

4343
**Note**: The output of the DOM is colorized by default if your tests are
4444
running in a node environment. However, you may sometimes want to turn off
45-
colors, such as in cases where the output is written to a log file for
46-
debugging purposes. You can use the environment variable `COLORS` to explicitly
47-
force the colorization off or on. For example:
45+
colors, such as in cases where the output is written to a log file for debugging
46+
purposes. You can use the environment variable `COLORS` to explicitly force the
47+
colorization off or on. For example:
4848

49-
```
49+
```bash npm2yarn
5050
COLORS=false npm test
5151
```
5252

@@ -105,9 +105,9 @@ This function is what also powers
105105
106106
## `screen.debug()`
107107
108-
For convenience `screen` also exposes a `debug` method.
109-
This method is essentially a shortcut for `console.log(prettyDOM())`. It
110-
supports debugging the document, a single element, or an array of elements.
108+
For convenience `screen` also exposes a `debug` method. This method is
109+
essentially a shortcut for `console.log(prettyDOM())`. It supports debugging the
110+
document, a single element, or an array of elements.
111111
112112
```javascript
113113
import {screen} from '@testing-library/dom'
@@ -129,8 +129,8 @@ screen.debug(screen.getAllByText('multi-test'))
129129
## `screen.logTestingPlaygroundURL()`
130130
131131
For debugging using [testing-playground](https://testing-playground.com), screen
132-
exposes this convenient method which logs and returns a URL that can be opened in
133-
a browser.
132+
exposes this convenient method which logs and returns a URL that can be opened
133+
in a browser.
134134
135135
```javascript
136136
import {screen} from '@testing-library/dom'

Diff for: docs/dom-testing-library/setup.mdx

+4-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ the DOM and browser APIs that runs in node. If you're not using Jest and you
1818
would like to run your tests in Node, then you must install jsdom yourself.
1919
There's also a package called
2020
[global-jsdom](https://github.com/modosc/global-jsdom) which can be used to
21-
setup the global environment to simulate the browser APIs. Note that if you're using
22-
Vitest you only need to configure [`environment`](https://vitest.dev/config/#environment)
23-
to `jsdom` to achieve the same effect, you don't need global-jsdom.
21+
setup the global environment to simulate the browser APIs. Note that if you're
22+
using Vitest you only need to configure
23+
[`environment`](https://vitest.dev/config/#environment) to `jsdom` to achieve
24+
the same effect, you don't need global-jsdom.
2425

2526
First, install jsdom and global-jsdom.
2627

Diff for: docs/example-external.mdx

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ sidebar_label: External Examples
66

77
## Code Samples
88

9-
- You can find more React Testing Library examples at [https://react-testing-examples.netlify.app/](https://react-testing-examples.netlify.app/).
9+
- You can find more React Testing Library examples at
10+
[https://react-testing-examples.netlify.app/](https://react-testing-examples.netlify.app/).
1011

1112
## Playground
1213

0 commit comments

Comments
 (0)