Skip to content

Commit

Permalink
fix(eslint-plugin): [switch-exhaustiveness-check] Add tests for new v…
Browse files Browse the repository at this point in the history
…alid identity check
  • Loading branch information
karishnu committed Jul 8, 2020
1 parent 27fd2d2 commit 5825e4a
Showing 1 changed file with 74 additions and 0 deletions.
Expand Up @@ -520,6 +520,80 @@ function test(arg: Enum): string {
case Enum['test-test']: { throw new Error('Not implemented yet: Enum['test-test'] case') }
case Enum.test: { throw new Error('Not implemented yet: Enum.test case') }
}
}
`.trimRight(),
},
],
},
],
},
{
// keys include empty string
code: `
export enum Enum {
'' = 'test-test',
'test' = 'test',
}
function test(arg: Enum): string {
switch (arg) {
}
}
`.trimRight(),
errors: [
{
messageId: 'switchIsNotExhaustive',
suggestions: [
{
messageId: 'addMissingCases',
output: noFormat`
export enum Enum {
'' = 'test-test',
'test' = 'test',
}
function test(arg: Enum): string {
switch (arg) {
case Enum['']: { throw new Error('Not implemented yet: Enum[''] case') }
case Enum.test: { throw new Error('Not implemented yet: Enum.test case') }
}
}
`.trimRight(),
},
],
},
],
},
{
// keys include number as first character
code: `
export enum Enum {
'9test' = 'test-test',
'test' = 'test',
}
function test(arg: Enum): string {
switch (arg) {
}
}
`.trimRight(),
errors: [
{
messageId: 'switchIsNotExhaustive',
suggestions: [
{
messageId: 'addMissingCases',
output: noFormat`
export enum Enum {
'9test' = 'test-test',
'test' = 'test',
}
function test(arg: Enum): string {
switch (arg) {
case Enum['9test']: { throw new Error('Not implemented yet: Enum['9test'] case') }
case Enum.test: { throw new Error('Not implemented yet: Enum.test case') }
}
}
`.trimRight(),
},
Expand Down

0 comments on commit 5825e4a

Please sign in to comment.