Files
NapCatQQ/.pnpm-store/v3/files/e6/c6af376bd9d772c5074f68322c2212aa50dae4e08bb9f95e65209eeddc39c0d7ac7b3c238fc93a815881e0b1e18957783c9024c12ac7f23cb6a1f82dab20fc
T
TanTan e311ca3275
Build NapCat Artifacts / Type Check & Test (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

86 lines
2.0 KiB
Plaintext

import test from 'tape';
import getTabIndex from '../../../src/util/getTabIndex';
import IdentifierMock from '../../../__mocks__/IdentifierMock';
import JSXAttributeMock from '../../../__mocks__/JSXAttributeMock';
test('getTabIndex', (t) => {
t.equal(
getTabIndex(JSXAttributeMock('tabIndex', 0)),
0,
'tabIndex is defined as zero -> zero',
);
t.equal(
getTabIndex(JSXAttributeMock('tabIndex', 1)),
1,
'tabIndex is defined as a positive integer -> returns it',
);
t.equal(
getTabIndex(JSXAttributeMock('tabIndex', -1)),
-1,
'tabIndex is defined as a negative integer -> returns it',
);
t.equal(
getTabIndex(JSXAttributeMock('tabIndex', '')),
undefined,
'tabIndex is defined as an empty string -> undefined',
);
t.equal(
getTabIndex(JSXAttributeMock('tabIndex', 9.1)),
undefined,
'tabIndex is defined as a float -> undefined',
);
t.equal(
getTabIndex(JSXAttributeMock('tabIndex', '0')),
0,
'tabIndex is defined as a string which converts to a number -> returns the integer',
);
t.equal(
getTabIndex(JSXAttributeMock('tabIndex', '0a')),
undefined,
'tabIndex is defined as a string which is NaN -> returns undefined',
);
t.equal(
getTabIndex(JSXAttributeMock('tabIndex', true)),
undefined,
'tabIndex is defined as true -> returns undefined',
);
t.equal(
getTabIndex(JSXAttributeMock('tabIndex', false)),
undefined,
'tabIndex is defined as false -> returns undefined',
);
t.equal(
typeof getTabIndex(JSXAttributeMock('tabIndex', () => 0)),
'function',
'tabIndex is defined as a function expression -> returns the correct type',
);
const name = 'identName';
t.equal(
getTabIndex(JSXAttributeMock(
'tabIndex',
IdentifierMock(name),
true,
)),
name,
'tabIndex is defined as a variable expression -> returns the Identifier name',
);
t.equal(
getTabIndex(JSXAttributeMock('tabIndex', undefined)),
undefined,
'tabIndex is not defined -> returns undefined',
);
t.end();
});