Skip to content

Commit

Permalink
Translation of testingerrorflows.md
Browse files Browse the repository at this point in the history
  • Loading branch information
forresst committed Dec 12, 2019
1 parent 8e91f3e commit 80343cd
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions sections/errorhandling/testingerrorflows.french.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# Test error flows using your favorite test framework
# Testez les flux d'erreurs en utilisant votre framework de test préféré

### One Paragraph Explainer
### Un paragraphe d'explication

Testing ‘happy’ paths is no better than testing failures. Good testing code coverage demands to test exceptional paths. Otherwise, there is no trust that exceptions are indeed handled correctly. Every unit testing framework, like [Mocha](https://mochajs.org/) & [Chai](http://chaijs.com/), supports exception testing (code examples below). If you find it tedious to test every inner function and exception you may settle with testing only REST API HTTP errors.
Tester les chemins « du bonheur » n’est pas mieux que de tester les échecs. Une bonne couverture du code de test exige de tester des chemins inhabituels. Sinon, il n'est pas certain que les exceptions soient effectivement gérées correctement. Chaque framework de tests unitaires, comme [Mocha](https://mochajs.org/) et [Chai](http://chaijs.com/), prend en charge les tests d'exception (exemples de code ci-dessous). Si vous trouvez fastidieux de tester chaque fonction interne et chaque exception, vous pouvez vous contenter de tester uniquement les erreurs HTTP de l'API REST.

### Code example: ensuring the right exception is thrown using Mocha & Chai
### Exemple de code : s'assurer que la bonne exception est levée à l'aide de Mocha & Chai

<details>
<summary><strong>Javascript</strong></summary>

```javascript
describe('Facebook chat', () => {
it('Notifies on new chat message', () => {
it('Avertit en cas de nouveau message dans la discussion', () => {
const chatService = new chatService();
chatService.participants = getDisconnectedParticipants();
expect(chatService.sendMessage.bind({ message: 'Hi' })).to.throw(ConnectionError);
expect(chatService.sendMessage.bind({ message: 'Salut' })).to.throw(ConnectionError);
});
});
```
Expand All @@ -25,22 +25,22 @@ describe('Facebook chat', () => {

```typescript
describe('Facebook chat', () => {
it('Notifies on new chat message', () => {
it('Avertit en cas de nouveau message dans la discussion', () => {
const chatService = new chatService();
chatService.participants = getDisconnectedParticipants();
expect(chatService.sendMessage.bind({ message: 'Hi' })).to.throw(ConnectionError);
expect(chatService.sendMessage.bind({ message: 'Salut' })).to.throw(ConnectionError);
});
});
```
</details>

### Code example: ensuring API returns the right HTTP error code
### Exemple de code: s'assurer que l'API renvoie le bon code erreur HTTP

<details>
<summary><strong>Javascript</strong></summary>

```javascript
it('Creates new Facebook group', () => {
it('Crée un nouveau groupe Facebook', () => {
const invalidGroupInfo = {};
return httpRequest({
method: 'POST',
Expand All @@ -49,7 +49,7 @@ it('Creates new Facebook group', () => {
body: invalidGroupInfo,
json: true
}).then((response) => {
expect.fail('if we were to execute the code in this block, no error was thrown in the operation above')
expect.fail('si nous devions exécuter le code dans ce bloc, aucune erreur n\'a été levée dans l\'opération ci-dessus')
}).catch((response) => {
expect(400).to.equal(response.statusCode);
});
Expand All @@ -61,7 +61,7 @@ it('Creates new Facebook group', () => {
<summary><strong>Typescript</strong></summary>

```typescript
it('Creates new Facebook group', async () => {
it('Crée un nouveau groupe Facebook', async () => {
let invalidGroupInfo = {};
try {
const response = await httpRequest({
Expand All @@ -71,8 +71,8 @@ it('Creates new Facebook group', async () => {
body: invalidGroupInfo,
json: true
})
// if we were to execute the code in this block, no error was thrown in the operation above
expect.fail('The request should have failed')
// si nous devions exécuter le code dans ce bloc, aucune erreur n'a été levée dans l'opération ci-dessus
expect.fail('La requête aurait dû échouer')
} catch(response) {
expect(400).to.equal(response.statusCode);
}
Expand Down

0 comments on commit 80343cd

Please sign in to comment.