Skip to content

Commit

Permalink
test: add more cases for coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath committed Apr 24, 2024
1 parent 24e2322 commit 5977f32
Showing 1 changed file with 136 additions and 4 deletions.
140 changes: 136 additions & 4 deletions src/rules/__tests__/padding-around-all.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { TSESLint } from '@typescript-eslint/utils';
import dedent from 'dedent';
import rule from '../padding-around-all';
import { FlatCompatRuleTester as RuleTester, espreeParser } from './test-utils';

Expand Down Expand Up @@ -90,8 +91,139 @@ describe('someText', () => {
} satisfies TSESLint.InvalidTestCase<'missingPadding', never>;

ruleTester.run('padding-around-all', rule, {
valid: [testCase.output],
invalid: ['src/component.test.jsx', 'src/component.test.js'].map(
filename => ({ ...testCase, filename }),
),
valid: [
testCase.output,
dedent`
xyz:
afterEach(() => {});
`,
],
invalid: [
...['src/component.test.jsx', 'src/component.test.js'].map(filename => ({
...testCase,
filename,
})),
{
code: dedent`
const someText = 'abc'
;afterEach(() => {})
`,
output: dedent`
const someText = 'abc'
;afterEach(() => {})
`,
errors: [
{
messageId: 'missingPadding',
line: 2,
column: 2,
},
],
},
{
code: dedent`
const someText = 'abc';
xyz:
afterEach(() => {});
`,
output: dedent`
const someText = 'abc';
xyz:
afterEach(() => {});
`,
errors: [
{
messageId: 'missingPadding',
line: 2,
column: 1,
},
],
},
{
code: dedent`
const expr = 'Papayas';
beforeEach(() => {});
it('does something?', () => {
switch (expr) {
case 'Oranges':
expect(expr).toBe('Oranges');
break;
case 'Mangoes':
case 'Papayas':
const v = 1;
expect(v).toBe(1);
console.log('Mangoes and papayas are $2.79 a pound.');
// Expected output: "Mangoes and papayas are $2.79 a pound."
break;
default:
console.log(\`Sorry, we are out of $\{expr}.\`);
}
});
`,
output: dedent`
const expr = 'Papayas';
beforeEach(() => {});
it('does something?', () => {
switch (expr) {
case 'Oranges':
expect(expr).toBe('Oranges');
break;
case 'Mangoes':
case 'Papayas':
const v = 1;
expect(v).toBe(1);
console.log('Mangoes and papayas are $2.79 a pound.');
// Expected output: "Mangoes and papayas are $2.79 a pound."
break;
default:
console.log(\`Sorry, we are out of $\{expr}.\`);
}
});
`,
errors: [
{
messageId: 'missingPadding',
line: 2,
column: 1,
endLine: 2,
endColumn: 22,
},
{
messageId: 'missingPadding',
line: 3,
column: 1,
endLine: 18,
endColumn: 4,
},
{
messageId: 'missingPadding',
line: 7,
column: 7,
endLine: 7,
endColumn: 13,
},
{
messageId: 'missingPadding',
line: 11,
column: 7,
endLine: 11,
endColumn: 25,
},
{
messageId: 'missingPadding',
line: 12,
column: 7,
endLine: 12,
endColumn: 61,
},
],
},
],
});

0 comments on commit 5977f32

Please sign in to comment.