Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

translate shallow renderer screen title and intro #28

Merged
merged 19 commits into from
Feb 28, 2019
Merged
Changes from 16 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
32 changes: 16 additions & 16 deletions content/docs/addons-shallow-renderer.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
---
id: shallow-renderer
title: Shallow Renderer
title: Rendu superficiel
mikaoelitiana marked this conversation as resolved.
Show resolved Hide resolved
permalink: docs/shallow-renderer.html
layout: docs
category: Reference
---

**Importing**
**Importation**

```javascript
import ShallowRenderer from 'react-test-renderer/shallow'; // ES6
var ShallowRenderer = require('react-test-renderer/shallow'); // ES5 with npm
var ShallowRenderer = require('react-test-renderer/shallow'); // ES5 avec npm
```

## Overview {#overview}
## Vue d'ensemble {#overview}
mikaoelitiana marked this conversation as resolved.
Show resolved Hide resolved

When writing unit tests for React, shallow rendering can be helpful. Shallow rendering lets you render a component "one level deep" and assert facts about what its render method returns, without worrying about the behavior of child components, which are not instantiated or rendered. This does not require a DOM.
Quand on écrit des tests unitaires pour React, le rendu superficiel peut être utile. Le rendu superficiel vous permet de réaliser le rendu d'un composant « à un seul niveau de profondeur » afin de pouvoir vérifier la qualité de ce que renvoie la fonction de rendu, sans se préoccuper des composants enfants, qui ne sont ni instanciés ni rendu. Cela ne nécessite donc pas de DOM.
mikaoelitiana marked this conversation as resolved.
Show resolved Hide resolved

For example, if you have the following component:
Par exemple, si vous avez le composant suivant :

```javascript
function MyComponent() {
return (
<div>
<span className="heading">Title</span>
<span className="heading">Titre</span>
<Subcomponent foo="bar" />
</div>
);
}
```

Then you can assert:
Vous pouvez alors faire les vérifications suivantes :

```javascript
import ShallowRenderer from 'react-test-renderer/shallow';

// in your test:
// dans votre test :
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Juste au-dessous, tu as oublié de retraduire le littéral « Titre » dans la grappe de test.

const renderer = new ShallowRenderer();
renderer.render(<MyComponent />);
const result = renderer.getRenderOutput();
Expand All @@ -47,22 +47,22 @@ expect(result.props.children).toEqual([
]);
```

Shallow testing currently has some limitations, namely not supporting refs.
Le rendu superficiel connait cependant quelques limites, notamment l'absence de support des refs.
mikaoelitiana marked this conversation as resolved.
Show resolved Hide resolved

> Note:
>
> We also recommend checking out Enzyme's [Shallow Rendering API](https://airbnb.io/enzyme/docs/api/shallow.html). It provides a nicer higher-level API over the same functionality.
> Nous vous conseillons par ailleurs de regarder [l'API de rendu superficiel](http://airbnb.io/enzyme/docs/api/shallow.html) (en anglais) d'Enzyme. Elle propose une meilleure API de haut niveau pour les même fonctionnalités.
mikaoelitiana marked this conversation as resolved.
Show resolved Hide resolved

## Reference {#reference}
## Référence {#reference}
mikaoelitiana marked this conversation as resolved.
Show resolved Hide resolved

### `shallowRenderer.render()` {#shallowrendererrender}

You can think of the shallowRenderer as a "place" to render the component you're testing, and from which you can extract the component's output.
Vous pouvez voir le shallowRenderer comme « l'endroit » où se fait le rendu du composant que vous testez et d'où vous pouvez extraire la sortie d'un composant.
mikaoelitiana marked this conversation as resolved.
Show resolved Hide resolved

`shallowRenderer.render()` is similar to [`ReactDOM.render()`](/docs/react-dom.html#render) but it doesn't require DOM and only renders a single level deep. This means you can test components isolated from how their children are implemented.
`shallowRenderer.render()` est comparable à [`ReactDOM.render()`](/docs/react-dom.html#render) sauf qu'il n'a pas besoin du DOM et effectue le rendu à un seul niveau de profondeur. Ça signifie que vous pouvez tester des composants indépendamment de l'implémentation de leurs enfants.
mikaoelitiana marked this conversation as resolved.
Show resolved Hide resolved

### `shallowRenderer.getRenderOutput()` {#shallowrenderergetrenderoutput}

After `shallowRenderer.render()` has been called, you can use `shallowRenderer.getRenderOutput()` to get the shallowly rendered output.
Après avoir appelé `shallowRenderer.render()`, vous pouvez utiliser `shallowRenderer.getRenderOutput()` pour récupérer le rendu superficiel obtenu.

You can then begin to assert facts about the output.
Vous pouvez alors vérifier la qualité du résultat attendu.
mikaoelitiana marked this conversation as resolved.
Show resolved Hide resolved