Total Complexity | 3 |
Complexity/F | 1 |
Lines of Code | 31 |
Function Count | 3 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import '@testing-library/jest-dom/extend-expect'; |
||
2 | import { render, screen } from '@testing-library/svelte'; |
||
3 | import { addMessages } from 'svelte-i18n'; |
||
4 | import ServerErrors from './ServerErrors.svelte'; |
||
5 | |||
6 | it('renders nothing with no error.', () => { |
||
7 | render(ServerErrors, { errors: [] }); |
||
8 | |||
9 | expect(screen.queryByText('Erreur')).not.toBeInTheDocument(); |
||
10 | }); |
||
11 | |||
12 | it('renders the given errors', () => { |
||
13 | addMessages('fr', { |
||
14 | first_error: 'Fichier non trouvé', |
||
15 | second_error: 'Saisie invalide', |
||
16 | }); |
||
17 | |||
18 | const errors = ['first_error', 'second_error']; |
||
19 | render(ServerErrors, { errors }); |
||
20 | |||
21 | const listItems = screen.getAllByRole('listitem'); |
||
22 | const listItemErrors = listItems.map((item) => item.textContent); |
||
23 | expect(listItems).toHaveLength(2); |
||
24 | expect(listItemErrors).toMatchInlineSnapshot(` |
||
25 | Array [ |
||
26 | "Fichier non trouvé", |
||
27 | "Saisie invalide", |
||
28 | ] |
||
29 | `); |
||
30 | expect(screen.getByText(/Erreur/i)).toBeInTheDocument(); |
||
31 | }); |
||
32 |