Skip to content

Commit 65512d6

Browse files
committed
Write tests for linkComponent settings
1 parent cab76f2 commit 65512d6

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ You should also specify settings that will be shared across all the plugin rules
4848
"forbidExtraProps",
4949
{"property": "freeze", "object": "Object"}
5050
{"property": "myFavoriteWrapper"}
51+
],
52+
"linkComponents": [
53+
// Components used as alternatives to <a> for linking, eg. <Link to={ url } />
54+
"Hyperlink",
55+
{"name": "Link", "linkAttribute": "to"}
5156
]
5257
}
5358
}

tests/lib/rules/jsx-no-target-blank.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ ruleTester.run('jsx-no-target-blank', rule, {
5555
{
5656
code: '<Link target="_blank" to={ dynamicLink }></Link>',
5757
options: [{enforceDynamicLinks: 'never', components: [{name: 'Link', linkAttribute: 'to'}]}]
58+
},
59+
{
60+
code: '<Link target="_blank" href={ dynamicLink }></Link>',
61+
options: [{enforceDynamicLinks: 'never'}],
62+
settings: {linkComponents: ['Link']}
63+
},
64+
{
65+
code: '<Link target="_blank" to={ dynamicLink }></Link>',
66+
options: [{enforceDynamicLinks: 'never'}],
67+
settings: {linkComponents: {name: 'Link', linkAttribute: 'to'}}
5868
}
5969
],
6070
invalid: [{
@@ -100,5 +110,17 @@ ruleTester.run('jsx-no-target-blank', rule, {
100110
code: '<Link target="_blank" to={ dynamicLink }></Link>',
101111
options: [{enforceDynamicLinks: 'always', components: [{name: 'Link', linkAttribute: 'to'}]}],
102112
errors: defaultErrors
113+
},
114+
{
115+
code: '<Link target="_blank" href={ dynamicLink }></Link>',
116+
options: [{enforceDynamicLinks: 'always'}],
117+
settings: {linkComponents: ['Link']},
118+
errors: defaultErrors
119+
},
120+
{
121+
code: '<Link target="_blank" to={ dynamicLink }></Link>',
122+
options: [{enforceDynamicLinks: 'always'}],
123+
settings: {linkComponents: {name: 'Link', linkAttribute: 'to'}},
124+
errors: defaultErrors
103125
}]
104126
});

0 commit comments

Comments
 (0)