getTabIndex-test.js
2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* eslint-env jest */
import getTabIndex from '../../../src/util/getTabIndex';
import IdentifierMock from '../../../__mocks__/IdentifierMock';
import JSXAttributeMock from '../../../__mocks__/JSXAttributeMock';
describe('getTabIndex', () => {
describe('tabIndex is defined', () => {
describe('as a number ', () => {
describe('zero', () => {
it('should return zero', () => {
expect(getTabIndex(JSXAttributeMock('tabIndex', 0))).toBe(0);
});
});
describe('positive integer', () => {
it('should return the integer', () => {
expect(getTabIndex(JSXAttributeMock('tabIndex', 1))).toBe(1);
});
});
describe('negative integer', () => {
it('should return the integer', () => {
expect(getTabIndex(JSXAttributeMock('tabIndex', -1))).toBe(-1);
});
});
describe('float', () => {
it('should return undefined', () => {
expect(getTabIndex(JSXAttributeMock('tabIndex', 9.1))).toBeUndefined();
});
});
});
describe('as a string', () => {
describe('empty', () => {
it('should return undefined', () => {
expect(getTabIndex(JSXAttributeMock('tabIndex', ''))).toBeUndefined();
});
});
describe('which converts to a number', () => {
it('should return an integer', () => {
expect(getTabIndex(JSXAttributeMock('tabIndex', '0'))).toBe(0);
});
});
describe('which is NaN', () => {
it('should return undefined', () => {
expect(getTabIndex(JSXAttributeMock('tabIndex', '0a'))).toBeUndefined();
});
});
});
describe('as a boolean', () => {
describe('true', () => {
it('should return undefined', () => {
expect(getTabIndex(JSXAttributeMock('tabIndex', true))).toBeUndefined();
});
});
describe('false', () => {
it('should return undefined', () => {
expect(getTabIndex(JSXAttributeMock('tabIndex', false))).toBeUndefined();
});
});
});
describe('as an expression', () => {
describe('function expression', () => {
it('should return the correct type', () => {
const attr = function mockFn() { return 0; };
expect(typeof getTabIndex(JSXAttributeMock('tabIndex', attr))).toEqual('function');
});
});
describe('variable expression', () => {
it('should return the Identifier name', () => {
const name = 'identName';
expect(getTabIndex(JSXAttributeMock(
'tabIndex',
IdentifierMock(name),
true,
))).toEqual(name);
});
});
});
});
describe('tabIndex is not defined', () => {
it('should return undefined', () => {
expect(getTabIndex(JSXAttributeMock('tabIndex', undefined))).toBeUndefined();
});
});
});