source: frontend/node_modules/eslint-plugin-jsx-a11y/__tests__/src/util/getTabIndex-test.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 2 weeks ago

Fix frontend appearance

  • Property mode set to 100644
File size: 2.0 KB
Line 
1import test from 'tape';
2
3import getTabIndex from '../../../src/util/getTabIndex';
4import IdentifierMock from '../../../__mocks__/IdentifierMock';
5import JSXAttributeMock from '../../../__mocks__/JSXAttributeMock';
6
7test('getTabIndex', (t) => {
8 t.equal(
9 getTabIndex(JSXAttributeMock('tabIndex', 0)),
10 0,
11 'tabIndex is defined as zero -> zero',
12 );
13
14 t.equal(
15 getTabIndex(JSXAttributeMock('tabIndex', 1)),
16 1,
17 'tabIndex is defined as a positive integer -> returns it',
18 );
19
20 t.equal(
21 getTabIndex(JSXAttributeMock('tabIndex', -1)),
22 -1,
23 'tabIndex is defined as a negative integer -> returns it',
24 );
25
26 t.equal(
27 getTabIndex(JSXAttributeMock('tabIndex', '')),
28 undefined,
29 'tabIndex is defined as an empty string -> undefined',
30 );
31
32 t.equal(
33 getTabIndex(JSXAttributeMock('tabIndex', 9.1)),
34 undefined,
35 'tabIndex is defined as a float -> undefined',
36 );
37
38 t.equal(
39 getTabIndex(JSXAttributeMock('tabIndex', '0')),
40 0,
41 'tabIndex is defined as a string which converts to a number -> returns the integer',
42 );
43
44 t.equal(
45 getTabIndex(JSXAttributeMock('tabIndex', '0a')),
46 undefined,
47 'tabIndex is defined as a string which is NaN -> returns undefined',
48 );
49
50 t.equal(
51 getTabIndex(JSXAttributeMock('tabIndex', true)),
52 undefined,
53 'tabIndex is defined as true -> returns undefined',
54 );
55 t.equal(
56 getTabIndex(JSXAttributeMock('tabIndex', false)),
57 undefined,
58 'tabIndex is defined as false -> returns undefined',
59 );
60
61 t.equal(
62 typeof getTabIndex(JSXAttributeMock('tabIndex', () => 0)),
63 'function',
64 'tabIndex is defined as a function expression -> returns the correct type',
65 );
66
67 const name = 'identName';
68 t.equal(
69 getTabIndex(JSXAttributeMock(
70 'tabIndex',
71 IdentifierMock(name),
72 true,
73 )),
74 name,
75 'tabIndex is defined as a variable expression -> returns the Identifier name',
76 );
77
78 t.equal(
79 getTabIndex(JSXAttributeMock('tabIndex', undefined)),
80 undefined,
81 'tabIndex is not defined -> returns undefined',
82 );
83
84 t.end();
85});
Note: See TracBrowser for help on using the repository browser.