Total Complexity | 3 |
Complexity/F | 1 |
Lines of Code | 42 |
Function Count | 3 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import '@testing-library/jest-dom/extend-expect'; |
||
2 | import {screen, render} from '@testing-library/svelte'; |
||
3 | import SecuredView from './SecuredView.svelte'; |
||
4 | import { |
||
5 | ROLE_COOPERATOR, |
||
6 | ROLE_EMPLOYEE, |
||
7 | ROLE_ACCOUNTANT |
||
8 | } from '../constants/roles'; |
||
9 | import {user} from '../store'; |
||
10 | |||
11 | beforeEach(() => { |
||
12 | jest.resetModules(); |
||
|
|||
13 | process.browser = true; |
||
14 | }); |
||
15 | |||
16 | it('renders the secured view for non-authorized user', () => { |
||
17 | user.set({ |
||
18 | role: ROLE_ACCOUNTANT |
||
19 | }); |
||
20 | |||
21 | const roles = [ROLE_COOPERATOR, ROLE_EMPLOYEE]; |
||
22 | |||
23 | render(SecuredView, { |
||
24 | roles |
||
25 | }); |
||
26 | |||
27 | expect(screen.getByText(/Accès interdit !/i)).toBeInTheDocument(); |
||
28 | }); |
||
29 | |||
30 | it('renders nothing for authorized user', () => { |
||
31 | user.set({ |
||
32 | role: ROLE_COOPERATOR |
||
33 | }); |
||
34 | |||
35 | const roles = [ROLE_COOPERATOR, ROLE_EMPLOYEE]; |
||
36 | |||
37 | render(SecuredView, { |
||
38 | roles |
||
39 | }); |
||
40 | |||
41 | expect(screen.queryByText(/Accès interdit !/i)).not.toBeInTheDocument(); |
||
42 | }); |
||
43 |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.