Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CJ Skillingstad committed Jan 11, 2018
1 parent 73c86c9 commit 9cc118c
Showing 1 changed file with 94 additions and 5 deletions.
99 changes: 94 additions & 5 deletions tests/lib/rules/jsx-tag-spacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,35 @@ function closingSlashOptions(option) {
return [{
closingSlash: option,
beforeSelfClosing: 'allow',
afterOpening: 'allow'
afterOpening: 'allow',
beforeClosing: 'allow'
}];
}

function beforeSelfClosingOptions(option) {
return [{
closingSlash: 'allow',
beforeSelfClosing: option,
afterOpening: 'allow'
afterOpening: 'allow',
beforeClosing: 'allow'
}];
}

function afterOpeningOptions(option) {
return [{
closingSlash: 'allow',
beforeSelfClosing: 'allow',
afterOpening: option
afterOpening: option,
beforeClosing: 'allow'
}];
}

function beforeClosingOptions(option) {
return [{
closingSlash: 'allow',
beforeSelfClosing: 'allow',
afterOpening: 'allow',
beforeClosing: option
}];
}

Expand Down Expand Up @@ -139,19 +151,46 @@ ruleTester.run('jsx-tag-spacing', rule, {
'App/>'
].join('\n'),
options: afterOpeningOptions('allow-multiline')
}, {
code: '<App />',
options: beforeClosingOptions('never')
}, {
code: '<App></App>',
options: beforeClosingOptions('never')
}, {
code: [
'<App',
'foo="bar"',
'>',
'</App>'
].join('\n'),
options: beforeClosingOptions('never')
}, {
code: '<App ></App >',
options: beforeClosingOptions('always')
}, {
code: [
'<App',
'foo="bar"',
'>',
'</App >'
].join('\n'),
options: beforeClosingOptions('always')
}, {
code: '<App/>',
options: [{
closingSlash: 'never',
beforeSelfClosing: 'never',
afterOpening: 'never'
afterOpening: 'never',
beforeClosing: 'never'
}]
}, {
code: '< App / >',
options: [{
closingSlash: 'always',
beforeSelfClosing: 'always',
afterOpening: 'always'
afterOpening: 'always',
beforeClosing: 'always'
}]
}],

Expand Down Expand Up @@ -306,5 +345,55 @@ ruleTester.run('jsx-tag-spacing', rule, {
output: '<App/>',
errors: [{message: 'A space is forbidden after opening bracket'}],
options: afterOpeningOptions('allow-multiline')
}, {
code: '<App ></App>',
output: '<App></App>',
errors: [{message: 'A space is forbidden before closing bracket'}],
options: beforeClosingOptions('never')
}, {
code: '<App></App >',
output: '<App></App>',
errors: [{message: 'A space is forbidden before closing bracket'}],
options: beforeClosingOptions('never')
}, {
code: [
'<App',
'foo="bar"',
'>',
'</App >'
].join('\n'),
output: [
'<App',
'foo="bar"',
'>',
'</App>'
].join('\n'),
errors: [{message: 'A space is forbidden before closing bracket'}],
options: beforeClosingOptions('never')
}, {
code: '<App></App >',
output: '<App ></App >',
errors: [{message: 'Whitespace is required before closing bracket'}],
options: beforeClosingOptions('always')
}, {
code: '<App ></App>',
output: '<App ></App >',
errors: [{message: 'Whitespace is required before closing bracket'}],
options: beforeClosingOptions('always')
}, {
code: [
'<App',
'foo="bar"',
'>',
'</App>'
].join('\n'),
output: [
'<App',
'foo="bar"',
'>',
'</App >'
].join('\n'),
errors: [{message: 'Whitespace is required before closing bracket'}],
options: beforeClosingOptions('always')
}]
});

0 comments on commit 9cc118c

Please sign in to comment.