Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npx lint-staged
2 changes: 1 addition & 1 deletion .node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16.14
24.16
3 changes: 1 addition & 2 deletions blog/2018-12-29-new-site.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
title: New Site
author: Alex Krolick
authorURL: 'http://github.com/alexkrolick'
authors: alexkrolick
---

We have a docs site now! It's built with [Docusaurus](https://docusaurus.io).
Expand Down
3 changes: 1 addition & 2 deletions blog/2019-03-17-code-blocks.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
title: Multi-Framework Code Blocks
author: Alex Krolick
authorURL: 'http://github.com/alexkrolick'
authors: alexkrolick
---

Many of the code samples have been updated to include tabs to switch between
Expand Down
6 changes: 1 addition & 5 deletions blog/2019-04-25-new-org.mdx
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
---
# prettier doesn't like how long this line is.: ""
# prettier-ignore: ""
title:
'Testing Library Updates: new release, github org, open collective, and
twitter account'
author: Kent C. Dodds
authorURL: 'https://kentcdodds.com'
authorImageURL: 'https://avatars0.githubusercontent.com/u/1500684?s=120&v=4'
authors: kentcdodds
---

Hello friends! I'm pleased to announce the recent updates to the testing-library
Expand Down
8 changes: 8 additions & 0 deletions blog/authors.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
alexkrolick:
name: Alex Krolick
url: http://github.com/alexkrolick

kentcdodds:
name: Kent C. Dodds
url: https://kentcdodds.com
image_url: https://avatars0.githubusercontent.com/u/1500684?s=120&v=4
26 changes: 12 additions & 14 deletions docs/angular-testing-library/api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ export async function render<WrapperType = WrapperComponent>(

## Component RenderOptions


### `inputs`

An object to set `@Input` or `input()` properties of the component.
Expand Down Expand Up @@ -122,26 +121,29 @@ await render(AppComponent, {

### `bindings`

An array of bindings to apply to the component using Angular's native bindings API. This provides a more direct way to bind inputs and outputs compared to the `inputs` and `on` options. The bindings API uses Angular's `inputBinding`, `outputBinding`, and `twoWayBinding` functions from `@angular/core`.
An array of bindings to apply to the component using Angular's native bindings
API. This provides a more direct way to bind inputs and outputs compared to the
`inputs` and `on` options. The bindings API uses Angular's `inputBinding`,
`outputBinding`, and `twoWayBinding` functions from `@angular/core`.

**default** : `[]`

```typescript
import { inputBinding, outputBinding, twoWayBinding, signal } from '@angular/core'
import {inputBinding, outputBinding, twoWayBinding, signal} from '@angular/core'

await render(AppComponent, {
bindings: [
// Bind a static input value
inputBinding('greeting', () => 'Hello'),

// Bind a signal as an input
inputBinding('age', () => 25),

// Two-way binding with a signal
twoWayBinding('name', signal('John')),

// Output binding with a callback
outputBinding('submitValue', (event) => console.log(event)),
outputBinding('submitValue', event => console.log(event)),
],
})
```
Expand All @@ -153,7 +155,7 @@ const greetingSignal = signal('Good day')
const nameSignal = signal('David')
const ageSignal = signal(35)

const { fixture } = await render(AppComponent, {
const {fixture} = await render(AppComponent, {
bindings: [
inputBinding('greeting', greetingSignal),
inputBinding('age', ageSignal),
Expand All @@ -171,9 +173,7 @@ greetingSignal.set('Good evening')
const submitHandler = jest.fn()

await render(AppComponent, {
bindings: [
outputBinding('submit', submitHandler),
],
bindings: [outputBinding('submit', submitHandler)],
})
```

Expand Down Expand Up @@ -449,7 +449,6 @@ await render(AppComponent, {
})
```


### ~~`componentInputs`~~ (deprecated)

An object to set `@Input` properties of the component. Uses `setInput` to set
Expand Down Expand Up @@ -506,7 +505,6 @@ await render(AppComponent, {
})
```


## `RenderResult`

### `container`
Expand Down Expand Up @@ -541,7 +539,7 @@ expect(screen.getByTestId('count-value').textContent).toBe('4')
expect(screen.getByTestId('name-value').textContent).toBe('Sarah')

await rerender({
inputs: {count: 7}
inputs: {count: 7},
})

// count is updated to 7
Expand Down
42 changes: 22 additions & 20 deletions docs/angular-testing-library/examples.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ title: Example
> or follow the
> [guided example](https://timdeschryver.dev/blog/getting-the-most-value-out-of-your-angular-component-tests)

Angular Testing Library can be used with standalone components and also with Angular components that uses Modules.
The example below shows how to test a standalone component, but the same principles apply to Angular components that uses Modules.
In fact, there should be no difference in how you test both types of components, only the setup might be different.
Angular Testing Library can be used with standalone components and also with
Angular components that uses Modules. The example below shows how to test a
standalone component, but the same principles apply to Angular components that
uses Modules. In fact, there should be no difference in how you test both types
of components, only the setup might be different.

```ts title="counter.component.ts"
@Component({
Expand All @@ -23,23 +25,23 @@ In fact, there should be no difference in how you test both types of components,
`,
})
export class CounterComponent {
counter = model(0);
hello = input('Hi', { alias: 'greeting' });
counter = model(0)
hello = input('Hi', {alias: 'greeting'})

increment() {
this.counter.set(this.counter() + 1);
this.counter.set(this.counter() + 1)
}

decrement() {
this.counter.set(this.counter() - 1);
this.counter.set(this.counter() - 1)
}
}
```

```typescript title="counter.component.spec.ts"
import { signal, inputBinding, twoWayBinding } from '@angular/core';
import { render, screen, fireEvent } from '@testing-library/angular';
import { CounterComponent } from './counter.component';
import {signal, inputBinding, twoWayBinding} from '@angular/core'
import {render, screen, fireEvent} from '@testing-library/angular'
import {CounterComponent} from './counter.component'

describe('Counter', () => {
it('renders counter', async () => {
Expand All @@ -49,23 +51,23 @@ describe('Counter', () => {
// aliases are handled naturally with inputBinding
inputBinding('greeting', () => 'Hello Alias!'),
],
});
})

expect(screen.getByText('Current Count: 5')).toBeVisible();
expect(screen.getByText('Hello Alias!')).toBeVisible();
});
expect(screen.getByText('Current Count: 5')).toBeVisible()
expect(screen.getByText('Hello Alias!')).toBeVisible()
})

it('increments the counter on click', async () => {
await render(CounterComponent, {
bindings: [twoWayBinding('counter', signal(5))],
});
})

const incrementButton = screen.getByRole('button', { name: '+' });
fireEvent.click(incrementButton);
const incrementButton = screen.getByRole('button', {name: '+'})
fireEvent.click(incrementButton)

expect(screen.getByText('Current Count: 6')).toBeVisible();
});
});
expect(screen.getByText('Current Count: 6')).toBeVisible()
})
})
```

## More examples
Expand Down
8 changes: 4 additions & 4 deletions docs/angular-testing-library/intro.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ sidebar_label: Introduction
[`Angular Testing Library`](https://github.com/testing-library/angular-testing-library)
builds on top of
[`DOM Testing Library`](https://github.com/testing-library/dom-testing-library)
by adding APIs for working with Angular components.
Starting from ATL version 17, you also need to install `@testing-library/dom`:
by adding APIs for working with Angular components. Starting from ATL version
17, you also need to install `@testing-library/dom`:

```bash npm2yarn
npm install --save-dev @testing-library/angular @testing-library/dom
```

Or, you can use the `ng add` command.
This sets up your project to use Angular Testing Library, which also includes the installation of `@testing-library/dom`.
Or, you can use the `ng add` command. This sets up your project to use Angular
Testing Library, which also includes the installation of `@testing-library/dom`.

```bash
ng add @testing-library/angular
Expand Down
3 changes: 2 additions & 1 deletion docs/cypress-testing-library/intro.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ Add this line to your project's `cypress/support/commands.js`:
import '@testing-library/cypress/add-commands'
```

You can now use some of `DOM Testing Library`'s `findBy`, and `findAllBy` commands off the global `cy` object.
You can now use some of `DOM Testing Library`'s `findBy`, and `findAllBy`
commands off the global `cy` object.
[See the `About queries` docs for reference](/docs/queries/about).

> Note: the `get*` queries are not supported because for reasonable Cypress
Expand Down
13 changes: 8 additions & 5 deletions docs/dom-testing-library/example-intro.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,16 @@ function getExampleDOM() {
button.addEventListener('click', () => {
// let's pretend this is making a server request, so it's async
// (you'd want to mock this imaginary request in your unit tests)...
setTimeout(() => {
const printedUsernameContainer = document.createElement('div')
printedUsernameContainer.innerHTML = `
setTimeout(
() => {
const printedUsernameContainer = document.createElement('div')
printedUsernameContainer.innerHTML = `
<div data-testid="printed-username">${input.value}</div>
`
div.appendChild(printedUsernameContainer)
}, Math.floor(Math.random() * 200))
div.appendChild(printedUsernameContainer)
},
Math.floor(Math.random() * 200),
)
})
return div
}
Expand Down
1 change: 0 additions & 1 deletion docs/example-react-intl.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ You have two options:
meaning it includes a subset of ICU data (typically only the English
locale).
If you do need to load a locale you have two options:

1. Load the Polyfills according to that language:

```js
Expand Down
8 changes: 4 additions & 4 deletions docs/marko-testing-library/intro.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ better testing practices. Its primary guiding principle is:

So rather than dealing with instances of rendered Marko components, your tests
will work with actual DOM nodes. The utilities this library provides facilitate
querying the DOM in the same way the user would. Finding elements by their
label text (just like a user would), finding links and buttons from their text
(like a user would). It contains a small targeted API and can get out of your
way if needed with some built-in escape hatches.
querying the DOM in the same way the user would. Finding elements by their label
text (just like a user would), finding links and buttons from their text (like a
user would). It contains a small targeted API and can get out of your way if
needed with some built-in escape hatches.

This library encourages your applications to be more accessible and allows you
to get your tests closer to using your components the way a user will, which
Expand Down
6 changes: 3 additions & 3 deletions docs/nightwatch-testing-library/intro.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ npm install --save-dev @testing-library/nightwatch

## READ THIS FIRST

At its core, `nightwatch-testing-library` translates between
dom-testing-library queries and css selectors. This is due to the fact that
Nightwatch adheres to the WebDriver standards for
At its core, `nightwatch-testing-library` translates between dom-testing-library
queries and css selectors. This is due to the fact that Nightwatch adheres to
the WebDriver standards for
[locator strategies](https://www.w3.org/TR/webdriver/#locator-strategies). For
now, this means that the logging will have some very detailed css paths. PRs
welcome for a
Expand Down
5 changes: 3 additions & 2 deletions docs/queries/about.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,9 @@ can contain options that affect the precision of string matching:
- `exact`: Defaults to `true`; matches full strings, case-sensitive. When false,
matches substrings and is not case-sensitive.
- it has no effect when used together with `regex` or `function` arguments.
- in most cases, using a regex instead of a string combined with `{ exact: false }`
gives you more control over fuzzy matching so it should be preferred.
- in most cases, using a regex instead of a string combined with
`{ exact: false }` gives you more control over fuzzy matching so it should
be preferred.
- `normalizer`: An optional function which overrides normalization behavior. See
[`Normalization`](#normalization).

Expand Down
2 changes: 1 addition & 1 deletion docs/queries/bytestid.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ getByTestId(
}): HTMLElement
```

A shortcut to `` container.querySelector(`[data-testid="${yourId}"]`) `` (and it
A shortcut to ``container.querySelector(`[data-testid="${yourId}"]`)`` (and it
also accepts a [`TextMatch`](queries/about.mdx#textmatch)).

```html
Expand Down
4 changes: 2 additions & 2 deletions docs/qwik-testing-library/example.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ title: Example
sidebar_label: Example
---

Below are some examples of how to use the Qwik Testing Library to test your
Qwik components.
Below are some examples of how to use the Qwik Testing Library to test your Qwik
components.

You can also learn more about the [**queries**][tl-queries-docs] and [**user
events**][tl-user-events-docs] to help you write your tests.
Expand Down
2 changes: 2 additions & 0 deletions docs/qwik-testing-library/setup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ with both `jsdom` and `happy-dom`:
```bash npm2yarn
npm install --save-dev jsdom
```

or

```bash npm2yarn
npm install --save-dev happy-dom
```
Expand Down
9 changes: 6 additions & 3 deletions docs/react-native-testing-library/example-intro.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ function Example() {
onPress={() => {
// let's pretend this is making a server request, so it's async
// (you'd want to mock this imaginary request in your unit tests)...
setTimeout(() => {
setShow(true)
}, Math.floor(Math.random() * 200))
setTimeout(
() => {
setShow(true)
},
Math.floor(Math.random() * 200),
)
}}
/>
{show && <Text testID="printed-username">{name}</Text>}
Expand Down
Loading