Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Validark committed Aug 8, 2019
1 parent 77b3b95 commit b906a23
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions packages/eslint-plugin/tests/rules/ban-types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,25 @@ const options: InferOptionsTypeFromRule<typeof rule> = [
},
},
];

const options2: InferOptionsTypeFromRule<typeof rule> = [
{
types: {
'null': {
message: 'Use undefined instead.',
fixWith: 'undefined',
},
},
},
];

const options3: InferOptionsTypeFromRule<typeof rule> = [
{
types: {
'undefined': null,
},
},
];

ruleTester.run('ban-types', rule, {
valid: [
Expand Down Expand Up @@ -51,6 +70,14 @@ ruleTester.run('ban-types', rule, {
code: 'let a: NS.Bad._',
options,
},
{
code: 'let a: undefined',
options: options2,
},
{
code: 'let a: null',
options: options3,
},
],
invalid: [
{
Expand All @@ -68,6 +95,30 @@ ruleTester.run('ban-types', rule, {
],
options,
},
{
code: 'let a: undefined;',
errors: [
{
messageId: 'bannedTypeMessage',
data: { name: 'undefined', customMessage: '' },
line: 1,
column: 8,
},
],
options: options3,
},
{
code: 'let a: null;',
errors: [
{
messageId: 'bannedTypeMessage',
data: { name: 'null', customMessage: ' Use undefined instead.' },
line: 1,
column: 8,
},
],
options: options2,
},
{
code: 'let aa: Foo;',
errors: [
Expand Down

0 comments on commit b906a23

Please sign in to comment.