Skip to content

Commit f7ce66f

Browse files
committed
test: add test case with settings['testing-library/utils-module'] configured
1 parent 6781117 commit f7ce66f

File tree

2 files changed

+119
-15
lines changed

2 files changed

+119
-15
lines changed

tests/lib/rules/no-node-access.test.ts

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,16 @@ ruleTester.run(RULE_NAME, rule, {
215215
code: `
216216
import { screen, fireEvent as fe } from '${testingFramework}';
217217
218+
const buttonText = screen.getByText('submit');
219+
fe.click(buttonText);
220+
`,
221+
},
222+
{
223+
settings: { 'testing-library/utils-module': 'test-utils' },
224+
code: `
225+
// case: custom module set but not imported using ${testingFramework} (aggressive reporting limited)
226+
import { screen, fireEvent as fe } from 'test-utils';
227+
218228
const buttonText = screen.getByText('submit');
219229
fe.click(buttonText);
220230
`,
@@ -457,24 +467,47 @@ ruleTester.run(RULE_NAME, rule, {
457467
},
458468
],
459469
},
460-
...EVENT_HANDLER_METHODS.map<RuleInvalidTestCase>((method) => ({
461-
code: `
470+
...EVENT_HANDLER_METHODS.flatMap<RuleInvalidTestCase>((method) => [
471+
{
472+
code: `
462473
import { screen } from '${testingFramework}';
463474
464475
const button = document.getElementById('submit-btn').${method}();
465476
`,
466-
errors: [
467-
{
468-
line: 4,
469-
column: 33,
470-
messageId: 'noNodeAccess',
471-
},
472-
{
473-
line: 4,
474-
column: 62,
475-
messageId: 'noNodeAccess',
476-
},
477-
],
478-
})),
477+
errors: [
478+
{
479+
line: 4,
480+
column: 33,
481+
messageId: 'noNodeAccess',
482+
},
483+
{
484+
line: 4,
485+
column: 62,
486+
messageId: 'noNodeAccess',
487+
},
488+
],
489+
},
490+
{
491+
settings: { 'testing-library/utils-module': 'test-utils' },
492+
code: `
493+
// case: custom module set but not imported using ${testingFramework} (aggressive reporting limited)
494+
import { screen } from 'test-utils';
495+
496+
const button = document.getElementById('submit-btn').${method}();
497+
`,
498+
errors: [
499+
{
500+
line: 5,
501+
column: 33,
502+
messageId: 'noNodeAccess',
503+
},
504+
{
505+
line: 5,
506+
column: 62,
507+
messageId: 'noNodeAccess',
508+
},
509+
],
510+
},
511+
]),
479512
]),
480513
});

tests/lib/utils/resolve-to-testing-library-fn.test.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ ruleTester.run('esm', rule, {
7373
userEvent.setup()
7474
`,
7575
},
76+
{
77+
settings: { 'testing-library/utils-module': 'test-utils' },
78+
code: `
79+
import { userEvent } from './test-utils';
80+
81+
userEvent.setup()
82+
`,
83+
},
7684
...LIBRARY_MODULES.map((module) => ({
7785
code: `
7886
import * as testingLibrary from '${module}';
@@ -101,6 +109,69 @@ ruleTester.run('esm', rule, {
101109
},
102110
],
103111
},
112+
{
113+
settings: { 'testing-library/utils-module': 'test-utils' },
114+
code: `
115+
import userEvent from 'test-utils';
116+
117+
userEvent.setup()
118+
`,
119+
errors: [
120+
{
121+
messageId: 'details',
122+
data: {
123+
data: {
124+
original: null,
125+
local: 'userEvent',
126+
},
127+
},
128+
},
129+
],
130+
},
131+
{
132+
settings: {
133+
'testing-library/custom-renders': ['customRender', 'renderWithRedux'],
134+
'testing-library/utils-module': 'test-utils',
135+
},
136+
code: `
137+
import { customRender } from 'test-utils';
138+
139+
customRender()
140+
`,
141+
errors: [
142+
{
143+
messageId: 'details',
144+
data: {
145+
data: {
146+
original: null,
147+
local: 'customRender',
148+
},
149+
},
150+
},
151+
],
152+
},
153+
{
154+
settings: {
155+
'testing-library/custom-queries': ['ByComplexText', 'queryByIcon'],
156+
'testing-library/utils-module': 'test-utils',
157+
},
158+
code: `
159+
import { queryByIcon } from 'test-utils';
160+
161+
queryByIcon()
162+
`,
163+
errors: [
164+
{
165+
messageId: 'details',
166+
data: {
167+
data: {
168+
original: null,
169+
local: 'queryByIcon',
170+
},
171+
},
172+
},
173+
],
174+
},
104175
...LIBRARY_MODULES.flatMap<InvalidTestCase<MessageIds, []>>((module) => [
105176
{
106177
code: `

0 commit comments

Comments
 (0)