Skip to content

Commit b6b14fe

Browse files
committed
test: add tests for isTestingLibraryModule
1 parent 4d152aa commit b6b14fe

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import {
2+
LIBRARY_MODULES,
3+
OLD_LIBRARY_MODULES,
4+
USER_EVENT_MODULE,
5+
} from '../../../lib/utils';
6+
import {
7+
isCustomTestingLibraryModule,
8+
isOfficialTestingLibraryModule,
9+
isTestingLibraryModule,
10+
} from '../../../lib/utils/is-testing-library-module';
11+
12+
describe('isOfficialTestingLibraryModule', () => {
13+
it.each([...OLD_LIBRARY_MODULES, ...LIBRARY_MODULES, USER_EVENT_MODULE])(
14+
'returns true when arg is "%s"',
15+
(importSourceName) => {
16+
const result = isOfficialTestingLibraryModule(importSourceName);
17+
18+
expect(result).toBe(true);
19+
}
20+
);
21+
22+
it.each(['custom-modules', 'hoge-testing-library', '@testing-library/hoge'])(
23+
'returns false when arg is "%s"',
24+
(importSourceName) => {
25+
const result = isOfficialTestingLibraryModule(importSourceName);
26+
27+
expect(result).toBe(false);
28+
}
29+
);
30+
});
31+
32+
describe('isCustomTestingLibraryModule', () => {
33+
it.each(['test-utils', '../test-utils', '@/test-utils'])(
34+
'returns true when arg is "%s"',
35+
(importSourceName) => {
36+
const result = isCustomTestingLibraryModule(
37+
importSourceName,
38+
'test-utils'
39+
);
40+
41+
expect(result).toBe(true);
42+
}
43+
);
44+
45+
it.each([
46+
'custom-modules',
47+
'react-testing-library',
48+
'@testing-library/react',
49+
'test-util',
50+
'test-utils-module',
51+
])('returns false when arg is "%s"', (importSourceName) => {
52+
const result = isCustomTestingLibraryModule(importSourceName, 'test-utils');
53+
54+
expect(result).toBe(false);
55+
});
56+
});
57+
58+
describe('isTestingLibraryModule', () => {
59+
it.each([
60+
...OLD_LIBRARY_MODULES,
61+
...LIBRARY_MODULES,
62+
USER_EVENT_MODULE,
63+
'test-utils',
64+
'../test-utils',
65+
'@/test-utils',
66+
])('returns true when arg is "%s"', (importSourceName) => {
67+
const result = isTestingLibraryModule(importSourceName, 'test-utils');
68+
69+
expect(result).toBe(true);
70+
});
71+
72+
it.each([
73+
'custom-modules',
74+
'hoge-testing-library',
75+
'@testing-library/hoge',
76+
'test-util',
77+
'test-utils-module',
78+
])('returns false when arg is "%s"', (importSourceName) => {
79+
const result = isTestingLibraryModule(importSourceName, 'test-utils');
80+
81+
expect(result).toBe(false);
82+
});
83+
});

0 commit comments

Comments
 (0)