Skip to content

Commit

Permalink
[Tests] jsx-no-script-url: Improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
radu2147 committed Nov 4, 2024
1 parent d1556a3 commit 3b961ea
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions tests/lib/rules/jsx-no-script-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ ruleTester.run('jsx-no-script-url', rule, {
{ code: '<a href={"javascript:"}></a>' },
{ code: '<Foo href="javascript:"></Foo>' },
{ code: '<a href />' },
{
code: '<Foo other="javascript:"></Foo>',
options: [[{ name: 'Foo', props: ['to', 'href'] }]],
},
{
code: '<Foo href="javascript:"></Foo>',
settings: {
Expand All @@ -51,6 +55,13 @@ ruleTester.run('jsx-no-script-url', rule, {
linkComponents: [{ name: 'Foo', linkAttribute: ['to', 'href'] }],
},
},
{
code: '<Foo other="javascript:"></Foo>',
options: [[], { includeFromSettings: true }],
settings: {
linkComponents: [{ name: 'Foo', linkAttribute: ['to', 'href'] }],
},
},
]),
invalid: parsers.all([
// defaults
Expand All @@ -71,23 +82,18 @@ ruleTester.run('jsx-no-script-url', rule, {
{
code: '<Foo to="javascript:"></Foo>',
errors: [{ messageId: 'noScriptURL' }],
options: [
[{ name: 'Foo', props: ['to', 'href'] }],
],
options: [[{ name: 'Foo', props: ['to', 'href'] }]],
},
{
code: '<Foo href="javascript:"></Foo>',
errors: [{ messageId: 'noScriptURL' }],
options: [
[{ name: 'Foo', props: ['to', 'href'] }],
],
options: [[{ name: 'Foo', props: ['to', 'href'] }]],
},
{ // make sure it still uses defaults when passed options
{
// make sure it still uses defaults when passed options
code: '<a href="javascript:void(0)"></a>',
errors: [{ messageId: 'noScriptURL' }],
options: [
[{ name: 'Foo', props: ['to', 'href'] }],
],
options: [[{ name: 'Foo', props: ['to', 'href'] }]],
},

// with components passed by settings
Expand Down Expand Up @@ -117,10 +123,7 @@ ruleTester.run('jsx-no-script-url', rule, {
<Bar link="javascript:"></Bar>
</div>
`,
errors: [
{ messageId: 'noScriptURL' },
{ messageId: 'noScriptURL' },
],
errors: [{ messageId: 'noScriptURL' }, { messageId: 'noScriptURL' }],
options: [
[{ name: 'Bar', props: ['link'] }],
{ includeFromSettings: true },
Expand All @@ -136,12 +139,8 @@ ruleTester.run('jsx-no-script-url', rule, {
<Bar link="javascript:"></Bar>
</div>
`,
errors: [
{ messageId: 'noScriptURL' },
],
options: [
[{ name: 'Bar', props: ['link'] }],
],
errors: [{ messageId: 'noScriptURL' }],
options: [[{ name: 'Bar', props: ['link'] }]],
settings: {
linkComponents: [{ name: 'Foo', linkAttribute: ['to', 'href'] }],
},
Expand Down

0 comments on commit 3b961ea

Please sign in to comment.