Skip to content

test: cleanup tests #588

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 51 additions & 38 deletions tests/lib/rules/no-await-sync-events.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ const FIRE_EVENT_FUNCTIONS = [
'gotPointerCapture',
'lostPointerCapture',
];
const SUPPORTED_TESTING_FRAMEWORKS = [
'@testing-library/dom',
'@testing-library/angular',
'@testing-library/react',
'@testing-library/vue',
'@marko/testing-library',
];
const USER_EVENT_SYNC_FUNCTIONS = [
'clear',
'click',
Expand Down Expand Up @@ -168,15 +175,17 @@ ruleTester.run(RULE_NAME, rule, {
},

// valid tests for fire-event when only user-event set in eventModules
...FIRE_EVENT_FUNCTIONS.map((func) => ({
code: `
import { fireEvent } from '@testing-library/framework';
test('should not report fireEvent.${func} sync event awaited', async() => {
await fireEvent.${func}('foo');
});
`,
options: [{ eventModules: ['user-event'] }],
})),
...SUPPORTED_TESTING_FRAMEWORKS.flatMap((testingFramework) =>
FIRE_EVENT_FUNCTIONS.map((func) => ({
code: `
import { fireEvent } from '${testingFramework}';
test('should not report fireEvent.${func} sync event awaited', async() => {
await fireEvent.${func}('foo');
});
`,
options: [{ eventModules: ['user-event'] }],
}))
),

// valid tests for user-event when only fire-event set in eventModules
...USER_EVENT_SYNC_FUNCTIONS.map((func) => ({
Expand All @@ -192,24 +201,26 @@ ruleTester.run(RULE_NAME, rule, {

invalid: [
// sync fireEvent methods with await operator are not valid
...FIRE_EVENT_FUNCTIONS.map(
(func) =>
({
code: `
import { fireEvent } from '@testing-library/framework';
...SUPPORTED_TESTING_FRAMEWORKS.flatMap((testingFramework) =>
FIRE_EVENT_FUNCTIONS.map(
(func) =>
({
code: `
import { fireEvent } from '${testingFramework}';
test('should report fireEvent.${func} sync event awaited', async() => {
await fireEvent.${func}('foo');
});
`,
errors: [
{
line: 4,
column: 17,
messageId: 'noAwaitSyncEvents',
data: { name: `fireEvent.${func}` },
},
],
} as const)
errors: [
{
line: 4,
column: 17,
messageId: 'noAwaitSyncEvents',
data: { name: `fireEvent.${func}` },
},
],
} as const)
)
),
// sync userEvent sync methods with await operator are not valid
...USER_EVENT_SYNC_FUNCTIONS.map(
Expand All @@ -234,25 +245,27 @@ ruleTester.run(RULE_NAME, rule, {

// sync fireEvent methods with await operator are not valid
// when only fire-event set in eventModules
...FIRE_EVENT_FUNCTIONS.map(
(func) =>
({
code: `
import { fireEvent } from '@testing-library/framework';
...SUPPORTED_TESTING_FRAMEWORKS.flatMap((testingFramework) =>
FIRE_EVENT_FUNCTIONS.map(
(func) =>
({
code: `
import { fireEvent } from '${testingFramework}';
test('should report fireEvent.${func} sync event awaited', async() => {
await fireEvent.${func}('foo');
});
`,
options: [{ eventModules: ['fire-event'] }],
errors: [
{
line: 4,
column: 17,
messageId: 'noAwaitSyncEvents',
data: { name: `fireEvent.${func}` },
},
],
} as const)
options: [{ eventModules: ['fire-event'] }],
errors: [
{
line: 4,
column: 17,
messageId: 'noAwaitSyncEvents',
data: { name: `fireEvent.${func}` },
},
],
} as const)
)
),
// sync userEvent sync methods with await operator are not valid
// when only fire-event set in eventModules
Expand Down
1 change: 0 additions & 1 deletion tests/lib/rules/no-promise-in-fire-event.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { createRuleTester } from '../test-utils';
const ruleTester = createRuleTester();

const SUPPORTED_TESTING_FRAMEWORKS = [
'@testing-library/foo',
'@testing-library/dom',
'@testing-library/angular',
'@testing-library/react',
Expand Down
1 change: 0 additions & 1 deletion tests/lib/rules/no-render-in-setup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { createRuleTester } from '../test-utils';
const ruleTester = createRuleTester();

const SUPPORTED_TESTING_FRAMEWORKS = [
'@testing-library/foo',
'@testing-library/angular',
'@testing-library/react',
'@testing-library/vue',
Expand Down
1 change: 0 additions & 1 deletion tests/lib/rules/prefer-find-by.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { createRuleTester } from '../test-utils';
const ruleTester = createRuleTester();

const SUPPORTED_TESTING_FRAMEWORKS = [
'@testing-library/foo',
'@testing-library/dom',
'@testing-library/angular',
'@testing-library/react',
Expand Down