Skip to content

Commit 545fad0

Browse files
committed
refactor: improve pagination test structure
1 parent f6e8cf0 commit 545fad0

File tree

1 file changed

+26
-23
lines changed

1 file changed

+26
-23
lines changed

packages/openapi-ts/src/ir/__tests__/pagination.test.ts

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { Config } from '../../types/config';
44
import { getPaginationKeywordsRegExp } from '../pagination';
55

66
describe('paginationKeywordsRegExp', () => {
7-
const scenarios: Array<{
7+
const defaultScenarios: Array<{
88
result: boolean;
99
value: string;
1010
}> = [
@@ -42,7 +42,7 @@ describe('paginationKeywordsRegExp', () => {
4242
},
4343
];
4444

45-
it.each(scenarios)(
45+
it.each(defaultScenarios)(
4646
'is $value pagination param? $output',
4747
async ({ result, value }) => {
4848
const paginationRegExp = getPaginationKeywordsRegExp();
@@ -51,27 +51,30 @@ describe('paginationKeywordsRegExp', () => {
5151
},
5252
);
5353

54-
it('uses custom keywords from config', async () => {
55-
const config: Config = {
56-
input: {
57-
pagination: {
58-
keywords: ['customPagination', 'pageSize', 'perPage'],
59-
},
60-
},
61-
} as Config;
62-
63-
const paginationRegExp = getPaginationKeywordsRegExp(config);
54+
const customScenarios: Array<{
55+
result: boolean;
56+
value: string;
57+
}> = [
58+
{ result: true, value: 'customPagination' },
59+
{ result: true, value: 'pageSize' },
60+
{ result: true, value: 'perPage' },
61+
{ result: false, value: 'page' },
62+
];
6463

65-
// Should match custom keywords
66-
paginationRegExp.lastIndex = 0;
67-
expect(paginationRegExp.test('customPagination')).toEqual(true);
68-
paginationRegExp.lastIndex = 0;
69-
expect(paginationRegExp.test('pageSize')).toEqual(true);
70-
paginationRegExp.lastIndex = 0;
71-
expect(paginationRegExp.test('perPage')).toEqual(true);
64+
it.each(customScenarios)(
65+
'with custom config, $value should match? $result',
66+
async ({ result, value }) => {
67+
const config: Config = {
68+
input: {
69+
pagination: {
70+
keywords: ['customPagination', 'pageSize', 'perPage'],
71+
},
72+
},
73+
} as Config;
7274

73-
// Should not match default keywords
74-
paginationRegExp.lastIndex = 0;
75-
expect(paginationRegExp.test('page')).toEqual(false);
76-
});
75+
const paginationRegExp = getPaginationKeywordsRegExp(config);
76+
paginationRegExp.lastIndex = 0;
77+
expect(paginationRegExp.test(value)).toEqual(result);
78+
},
79+
);
7780
});

0 commit comments

Comments
 (0)