Skip to content

Commit

Permalink
test: add destructuring test cases for computed-property-spacing (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Dec 14, 2021
1 parent f13d4a6 commit 225f211
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions tests/lib/rules/computed-property-spacing.js
Expand Up @@ -265,7 +265,30 @@ ruleTester.run("computed-property-spacing", rule, {
].join("\n"),
options: ["never"],
parserOptions: { ecmaVersion: 6 }
},

// Destructuring Assignment
{
code: "const { [a]: someProp } = obj;",
options: ["never"],
parserOptions: { ecmaVersion: 6 }
},
{
code: "({ [a]: someProp } = obj);",
options: ["never"],
parserOptions: { ecmaVersion: 6 }
},
{
code: "const { [ a ]: someProp } = obj;",
options: ["always"],
parserOptions: { ecmaVersion: 6 }
},
{
code: "({ [ a ]: someProp } = obj);",
options: ["always"],
parserOptions: { ecmaVersion: 6 }
}

],

invalid: [
Expand Down Expand Up @@ -2062,6 +2085,66 @@ ruleTester.run("computed-property-spacing", rule, {
{ messageId: "unexpectedSpaceAfter", data: { tokenValue: "[" } },
{ messageId: "unexpectedSpaceBefore", data: { tokenValue: "]" } }
]
},

// Destructuring Assignment
{
code: "const { [ a]: someProp } = obj;",
output: "const { [a]: someProp } = obj;",
options: ["never"],
parserOptions: { ecmaVersion: 2022 },
errors: [
{ messageId: "unexpectedSpaceAfter", data: { tokenValue: "[" } }
]
},
{
code: "const { [a ]: someProp } = obj;",
output: "const { [a]: someProp } = obj;",
options: ["never"],
parserOptions: { ecmaVersion: 2022 },
errors: [
{ messageId: "unexpectedSpaceBefore", data: { tokenValue: "]" } }
]
},
{
code: "const { [ a ]: someProp } = obj;",
output: "const { [a]: someProp } = obj;",
options: ["never"],
parserOptions: { ecmaVersion: 2022 },
errors: [
{ messageId: "unexpectedSpaceAfter", data: { tokenValue: "[" } },
{ messageId: "unexpectedSpaceBefore", data: { tokenValue: "]" } }
]
},
{
code: "({ [ a ]: someProp } = obj);",
output: "({ [a]: someProp } = obj);",
options: ["never"],
parserOptions: { ecmaVersion: 2022 },
errors: [
{ messageId: "unexpectedSpaceAfter", data: { tokenValue: "[" } },
{ messageId: "unexpectedSpaceBefore", data: { tokenValue: "]" } }
]
},
{
code: "const { [a]: someProp } = obj;",
output: "const { [ a ]: someProp } = obj;",
options: ["always"],
parserOptions: { ecmaVersion: 2022 },
errors: [
{ messageId: "missingSpaceAfter", data: { tokenValue: "[" } },
{ messageId: "missingSpaceBefore", data: { tokenValue: "]" } }
]
},
{
code: "({ [a]: someProp } = obj);",
output: "({ [ a ]: someProp } = obj);",
options: ["always"],
parserOptions: { ecmaVersion: 2022 },
errors: [
{ messageId: "missingSpaceAfter", data: { tokenValue: "[" } },
{ messageId: "missingSpaceBefore", data: { tokenValue: "]" } }
]
}
]
});

0 comments on commit 225f211

Please sign in to comment.