Skip to content

Commit

Permalink
jsx-no-target-blank Add tests for new config, links and forms
Browse files Browse the repository at this point in the history
  • Loading branch information
jaaberg committed Dec 19, 2017
1 parent fb7c685 commit b77a762
Showing 1 changed file with 48 additions and 5 deletions.
53 changes: 48 additions & 5 deletions tests/lib/rules/jsx-no-target-blank.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,25 @@ ruleTester.run('jsx-no-target-blank', rule, {
{code: '<a target={targetValue} rel="noopener noreferrer"></a>'},
{code: '<a target={targetValue} href="relative/path"></a>'},
{code: '<a target={targetValue} href="/absolute/path"></a>'},
{code: '<form action="http://example.com" target="_blank"></form>'},
{
code: '<a target="_blank" href="/absolute/path"></a>',
options: [{forms: false}]
},
{
code: '<a target="_blank" href="/absolute/path"></a>',
options: [{forms: false, links: true}]
},
{
code: '<form action="http://example.com" target="_blank"></form>',
options: []
},
{
code: '<form action="http://example.com" target="_blank" rel="noopener noreferrer"></form>',
options: [{forms: true}]
},
{
code: '<form action="http://example.com" target="_blank" rel="noopener noreferrer"></form>',
options: [{preventInForms: true}]
options: [{forms: true, links: false}]
}
],
invalid: [{
Expand Down Expand Up @@ -99,23 +114,51 @@ ruleTester.run('jsx-no-target-blank', rule, {
message: 'Using target="_blank" without rel="noopener noreferrer" is a security risk:' +
' see https://mathiasbynens.github.io/rel-noopener'
}]
}, {
code: '<a target="_blank" href="//example.com" rel></a>',
options: [{links: true}],
errors: [{
message: 'Using target="_blank" without rel="noopener noreferrer" is a security risk:' +
' see https://mathiasbynens.github.io/rel-noopener'
}]
}, {
code: '<a target="_blank" href="//example.com" rel></a>',
options: [{links: true, forms: true}],
errors: [{
message: 'Using target="_blank" without rel="noopener noreferrer" is a security risk:' +
' see https://mathiasbynens.github.io/rel-noopener'
}]
}, {
code: '<a target="_blank" href="//example.com" rel></a>',
options: [{links: true, forms: false}],
errors: [{
message: 'Using target="_blank" without rel="noopener noreferrer" is a security risk:' +
' see https://mathiasbynens.github.io/rel-noopener'
}]
}, {
code: '<form method="POST" action="http://example.com" target="_blank"></form>',
options: [{preventInForms: true}],
options: [{forms: true}],
errors: [{
message: 'Using target="_blank" without rel="noopener noreferrer" is a security risk:' +
' see https://mathiasbynens.github.io/rel-noopener'
}]
}, {
code: '<form method="POST" action="http://example.com" rel="" target="_blank"></form>',
options: [{preventInForms: true}],
options: [{forms: true}],
errors: [{
message: 'Using target="_blank" without rel="noopener noreferrer" is a security risk:' +
' see https://mathiasbynens.github.io/rel-noopener'
}]
}, {
code: '<form method="POST" action="http://example.com" rel="noopenernoreferrer" target="_blank"></form>',
options: [{forms: true}],
errors: [{
message: 'Using target="_blank" without rel="noopener noreferrer" is a security risk:' +
' see https://mathiasbynens.github.io/rel-noopener'
}]
}, {
code: '<form method="POST" action="http://example.com" rel="noopenernoreferrer" target="_blank"></form>',
options: [{preventInForms: true}],
options: [{forms: true, links: false}],
errors: [{
message: 'Using target="_blank" without rel="noopener noreferrer" is a security risk:' +
' see https://mathiasbynens.github.io/rel-noopener'
Expand Down

0 comments on commit b77a762

Please sign in to comment.