Skip to content

Commit

Permalink
test: add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
lsndr committed Apr 12, 2024
1 parent 3ca47ef commit 1fc2cc6
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/rule.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { RuleTester } from '@typescript-eslint/rule-tester';
import { rule } from './rule';
import * as path from 'path';

describe('Rule', () => {
const tester = new RuleTester({
parser: '@typescript-eslint/parser',
parserOptions: {
project: './tsconfig.json',
tsconfigRootDir: path.resolve(__dirname, '..')
}
});

tester.run('no-inheritance', rule, {
valid: [
'abstract class Grandparent {} abstract class Parent extends Grandparent {} class Child extends Parent {}',
'abstract class Parent {} class Child extends Parent {}',
'interface Type {} class Child implements Type {}',
'interface Type {} abstract class Parent {} class Child extends Parent implements Type {}',
{
code: 'abstract class Parent {} class Child extends Parent {}',
options: [{ noInheritanceOfAbstractClasses: false }]
}
],
invalid: [
{
code: 'class Parent {} class Child extends Parent {}',
errors: [{ messageId: 'inheritanceNotAllowed' }],
},
{
code: 'abstract class Parent {} class Child extends Parent {}',
errors: [{ messageId: 'inheritanceNotAllowed' }],
options: [{ noInheritanceOfAbstractClasses: true }]
},
{
code: 'class Grandparent {} abstract class Parent extends Grandparent {} class Child extends Parent {}',
errors: [{ messageId: 'inheritanceNotAllowed' }],
},
],
});
});


0 comments on commit 1fc2cc6

Please sign in to comment.