Skip to content

Commit

Permalink
Chore: Add object-property-newline tests to increase coverage. (#9553)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrpool authored and ilyavolodin committed Nov 1, 2017
1 parent 7f37b1c commit 88d2303
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions tests/lib/rules/object-property-newline.js
Expand Up @@ -24,7 +24,9 @@ ruleTester.run("object-property-newline", rule, {

// default-case
"var obj = {\nk1: 'val1',\nk2: 'val2',\nk3: 'val3',\nk4: 'val4'\n};",
"var obj = {\nk1: 'val1'\n, k2: 'val2'\n, k3: 'val3'\n, k4: 'val4'\n};",
"var obj = { k1: 'val1',\nk2: 'val2',\nk3: 'val3',\nk4: 'val4' };",
"var obj = { k1: 'val1'\n, k2: 'val2'\n, k3: 'val3'\n, k4: 'val4' };",
"var obj = { k1: 'val1' };",
"var obj = {\nk1: 'val1'\n};",
"var obj = {};",
Expand Down Expand Up @@ -173,6 +175,18 @@ ruleTester.run("object-property-newline", rule, {
}
]
},
{
code: "var obj = { k1: 'val1',\nk2: [\n'val2a', 'val2b', 'val2c'\n], k3: 'val3' };",
output: "var obj = { k1: 'val1',\nk2: [\n'val2a', 'val2b', 'val2c'\n],\nk3: 'val3' };",
errors: [
{
message: "Object properties must go on a new line.",
type: "ObjectExpression",
line: 4,
column: 4
}
]
},
{
code: "var obj = { k1: 'val1', [\nk2]: 'val2' };",
output: "var obj = { k1: 'val1',\n[\nk2]: 'val2' };",
Expand Down Expand Up @@ -378,6 +392,25 @@ ruleTester.run("object-property-newline", rule, {
}
]
},
{
code: "var obj = {\nk1:\n'val1', k2: 'val2', k3:\n'val3'\n};",
output: "var obj = {\nk1:\n'val1',\nk2: 'val2',\nk3:\n'val3'\n};",
options: [{ allowMultiplePropertiesPerLine: true }],
errors: [
{
message: "Object properties must go on a new line if they aren't all on the same line.",
type: "ObjectExpression",
line: 3,
column: 9
},
{
message: "Object properties must go on a new line if they aren't all on the same line.",
type: "ObjectExpression",
line: 3,
column: 21
}
]
},
{
code: "var obj = {k1: [\n'foo',\n'bar'\n], k2: 'val1'};",
output: "var obj = {k1: [\n'foo',\n'bar'\n],\nk2: 'val1'};",
Expand Down Expand Up @@ -423,6 +456,19 @@ ruleTester.run("object-property-newline", rule, {
}
]
},
{
code: "var obj = { k1: 'val1',\nk2: [\n'val2a', 'val2b', 'val2c'\n], k3: 'val3' };",
output: "var obj = { k1: 'val1',\nk2: [\n'val2a', 'val2b', 'val2c'\n],\nk3: 'val3' };",
options: [{ allowMultiplePropertiesPerLine: true }],
errors: [
{
message: "Object properties must go on a new line if they aren't all on the same line.",
type: "ObjectExpression",
line: 4,
column: 4
}
]
},
{
code: "var obj = { [\nk1]: 'val1', k2: 'val2' };",
output: "var obj = { [\nk1]: 'val1',\nk2: 'val2' };",
Expand Down

0 comments on commit 88d2303

Please sign in to comment.