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 6 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 faire le rendu d'un composant « à un seul niveau de profondeur » afin vérifier des faits sur le retour de 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:
Si vous avez par exemple le composant suivant:
mikaoelitiana marked this conversation as resolved.
Show resolved Hide resolved

```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 vérifier les faits comme suit:
mikaoelitiana marked this conversation as resolved.
Show resolved Hide resolved

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

// in your test:
// dans votre test:
mikaoelitiana marked this conversation as resolved.
Show resolved Hide resolved
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](http://airbnb.io/enzyme/docs/api/shallow.html). It provides a nicer higher-level API over the same functionality.
> Nous vous recommandons de voir l'API du rendu superficiel de Enzyme [Shallow Rendering API](http://airbnb.io/enzyme/docs/api/shallow.html). Il 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éference {#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. Cela signifie que vous pouvez tester des composants séparément 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 la sortie du superficiel.
mikaoelitiana marked this conversation as resolved.
Show resolved Hide resolved

You can then begin to assert facts about the output.
Vous pouvez alors vérifier des faits sur cette sortie.
mikaoelitiana marked this conversation as resolved.
Show resolved Hide resolved