Skip to content

Commit 1423db5

Browse files
committed
Merge branch 'main' into dont-install-dom
2 parents 0c9a786 + bfbf510 commit 1423db5

File tree

26 files changed

+187
-165
lines changed

26 files changed

+187
-165
lines changed

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).

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

docs/angular-testing-library/version-compatibility.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ 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
| ------- | ----------------------- |
1011
| 16.x | 13.x \|\| 14.x |
1112
| >= 15.1 | 13.x \|\| 14.x |
1213
| < 15.1 | 11.x \|\| 12.x |
1314
| 14.x | 11.x \|\| 12.x |
14-

docs/dom-testing-library/api-debugging.mdx

+8-8
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ 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

4949
```
5050
COLORS=false npm test
@@ -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'

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

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

docs/example-formik.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,12 @@ test('rendering and submitting a basic Formik form', async () => {
6565
render(<MyForm onSubmit={handleSubmit} />)
6666
const user = userEvent.setup()
6767

68-
await user.type(screen.getByRole("textbox", { name: /first name/i }), 'John')
69-
await user.type(screen.getByRole("textbox", { name: /last name/i }), 'Dee')
70-
await user.type(screen.getByRole("textbox", { name: /email/i }), '[email protected]')
68+
await user.type(screen.getByRole('textbox', {name: /first name/i}), 'John')
69+
await user.type(screen.getByRole('textbox', {name: /last name/i}), 'Dee')
70+
await user.type(
71+
screen.getByRole('textbox', {name: /email/i}),
72+
73+
)
7174

7275
await user.click(screen.getByRole('button', {name: /submit/i}))
7376

docs/example-react-router.mdx

+2-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ export const App = () => (
168168
```
169169

170170
In your tests, pass the history object as a whole to the Router component.
171-
**Note:** React Router v5 [only works with History v4](https://github.com/remix-run/history#documentation),
171+
**Note:** React Router v5
172+
[only works with History v4](https://github.com/remix-run/history#documentation),
172173
so make sure you have the correct version of `history` installed.
173174

174175
```jsx

docs/learning.mdx

+10-5
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,14 @@ sidebar_label: Learning Material
4343
[Daniel Afonso](https://twitter.com/danieljcafonso)
4444
- [Testing Apollo Components Using react-testing-library](https://www.arahansen.com/testing-apollo-components-using-react-testing-library/)
4545
by [Andrew Hansen](https://twitter.com/arahansen)
46-
- [Enzyme vs React Testing Library: A Migration Guide](https://claritydev.net/blog/enzyme-vs-react-testing-library-migration-guide) by [Alex Khomenko](https://claritydev.net)
47-
- [Testing React Hook Form With React Testing Library](https://claritydev.net/blog/testing-react-hook-form-with-react-testing-library) by [Alex Khomenko](https://claritydev.net)
48-
- [Improving React Testing Library Tests](https://claritydev.net/blog/improving-react-testing-library-tests) by [Alex Khomenko](https://claritydev.net)
49-
- [Testing Angular Challenges](https://angular-challenges.vercel.app/challenges/testing/) by [Thomas Laforge](https://twitter.com/laforge_toma)
46+
- [Enzyme vs React Testing Library: A Migration Guide](https://claritydev.net/blog/enzyme-vs-react-testing-library-migration-guide)
47+
by [Alex Khomenko](https://claritydev.net)
48+
- [Testing React Hook Form With React Testing Library](https://claritydev.net/blog/testing-react-hook-form-with-react-testing-library)
49+
by [Alex Khomenko](https://claritydev.net)
50+
- [Improving React Testing Library Tests](https://claritydev.net/blog/improving-react-testing-library-tests)
51+
by [Alex Khomenko](https://claritydev.net)
52+
- [Testing Angular Challenges](https://angular-challenges.vercel.app/challenges/testing/)
53+
by [Thomas Laforge](https://twitter.com/laforge_toma)
5054

5155
## Portuguese 🇧🇷
5256

@@ -61,6 +65,7 @@ sidebar_label: Learning Material
6165

6266
- [TESTING en REACT 🧪 ¡Aprende DESDE CERO! Con react-testing-library y Jest](https://www.youtube.com/watch?v=KYjjtRgg_H0)
6367
by [Midudev](https://twitter.com/midudev)
64-
- [Buenas prácticas con Angular Testing Library](https://dev.to/danyparedes/buenas-practicas-con-angular-testing-library-59lp) by [Danywalls](https://twitter.com/danywalls)
68+
- [Buenas prácticas con Angular Testing Library](https://dev.to/danyparedes/buenas-practicas-con-angular-testing-library-59lp)
69+
by [Danywalls](https://twitter.com/danywalls)
6570

6671
Feel free to contribute more!

docs/preact-testing-library/api.mdx

+13-11
Original file line numberDiff line numberDiff line change
@@ -93,23 +93,25 @@ give you an idea of how to test using those functions.
9393
### Example 1
9494

9595
```jsx
96-
const cb = jest.fn();
96+
const cb = jest.fn()
9797

9898
function Counter() {
99-
useEffect(cb);
99+
useEffect(cb)
100100

101-
const [count, setCount] = useState(0);
101+
const [count, setCount] = useState(0)
102102

103-
return <button onClick={() => setCount(count + 1)}>{count}</button>;
103+
return <button onClick={() => setCount(count + 1)}>{count}</button>
104104
}
105105

106-
const { container: { firstChild: buttonNode }, } = render(<Counter />);
106+
const {
107+
container: {firstChild: buttonNode},
108+
} = render(<Counter />)
107109

108110
// Clear the first call to useEffect that the initial render triggers.
109-
cb.mockClear();
111+
cb.mockClear()
110112

111113
// Fire event Option 1.
112-
fireEvent.click(buttonNode);
114+
fireEvent.click(buttonNode)
113115

114116
// Fire event Option 2.
115117
fireEvent(
@@ -118,11 +120,11 @@ fireEvent(
118120
bubbles: true,
119121
cancelable: true,
120122
button: 0,
121-
})
122-
);
123+
}),
124+
)
123125

124-
expect(buttonNode).toHaveTextContent('1');
125-
expect(cb).toHaveBeenCalledTimes(1);
126+
expect(buttonNode).toHaveTextContent('1')
127+
expect(cb).toHaveBeenCalledTimes(1)
126128
```
127129

128130
### Example 2

docs/queries/byrole.mdx

+3-2
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,8 @@ specific value using the `level` option
373373
`getByRole('spinbutton', { value: { now: 5, min: 0, max: 10, text: 'medium' } })`.
374374

375375
Note that you don't have to specify all properties in `value`. A subset is
376-
sufficient e.g. `getByRole('spinbutton', { value: { now: 5, text: 'medium' } })`.
376+
sufficient e.g.
377+
`getByRole('spinbutton', { value: { now: 5, text: 'medium' } })`.
377378

378379
Given the example below,
379380

@@ -416,7 +417,7 @@ getAllByRole('spinbutton', {value: {min: 0}})
416417
```
417418

418419
> Every specified property in `value` must match. For example, if you query for
419-
> `{value: {min: 0, now: 3}}` `aria-valuemin` must be equal to 0 **AND**
420+
> `{value: {min: 0, now: 3}}` `aria-valuemin` must be equal to 0 **AND** >
420421
> `aria-valuenow` must be equal to 3
421422
422423
> The `value` option is _only_ applicable to certain roles (check the linked MDN

docs/react-native-testing-library/example-intro.mdx

+5-5
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,18 @@ function Example() {
3333

3434
test('examples of some things', async () => {
3535
const expectedUsername = 'Ada Lovelace'
36-
36+
3737
render(<Example />)
3838

3939
fireEvent.changeText(screen.getByTestId('input'), expectedUsername)
4040
fireEvent.press(screen.getByText('Print Username'))
41-
41+
4242
// Using `findBy` query to wait for asynchronous operation to finish
4343
const usernameOutput = await screen.findByTestId('printed-username')
44-
44+
4545
// Using `toHaveTextContent` matcher from `@testing-library/jest-native` package.
46-
expect(usernameOutput).toHaveTextContent(expectedUsername);
47-
46+
expect(usernameOutput).toHaveTextContent(expectedUsername)
47+
4848
expect(screen.toJSON()).toMatchSnapshot()
4949
})
5050
```

docs/react-testing-library/api.mdx

+8-6
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ function renderHook<
339339
Props,
340340
Q extends Queries = typeof queries,
341341
Container extends Element | DocumentFragment = HTMLElement,
342-
BaseElement extends Element | DocumentFragment = Container,
342+
BaseElement extends Element | DocumentFragment = Container
343343
>(
344344
render: (initialProps: Props) => Result,
345345
options?: RenderHookOptions<Props, Q, Container, BaseElement>,
@@ -377,18 +377,20 @@ test('returns logged in user', () => {
377377
})
378378
```
379379
380-
> NOTE: When using `renderHook` in conjunction with the `wrapper` and `initialProps` options, the `initialProps` are not passed to the `wrapper` component.
381-
> To provide props to the `wrapper` component, consider a solution like this:
380+
> NOTE: When using `renderHook` in conjunction with the `wrapper` and
381+
> `initialProps` options, the `initialProps` are not passed to the `wrapper`
382+
> component. To provide props to the `wrapper` component, consider a solution
383+
> like this:
382384
>
383385
> ```js
384386
> const createWrapper = (Wrapper, props) => {
385387
> return function CreatedWrapper({ children }) {
386388
> return <Wrapper {...props}>{children}</Wrapper>;
387389
> };
388390
> };
389-
>
391+
>
390392
> ...
391-
>
393+
>
392394
> {
393395
> wrapper: createWrapper(Wrapper, { value: 'foo' }),
394396
> }
@@ -449,4 +451,4 @@ import {renderHook} from '@testing-library/react'
449451
const {unmount} = renderHook(({name = 'Alice'} = {}) => name)
450452

451453
unmount()
452-
```
454+
```

0 commit comments

Comments
 (0)