eslint-plugin-custom-elements/test/no-method-prefixed-with-on.js

63 строки
1.8 KiB
JavaScript
Исходник Постоянная ссылка Обычный вид История

const rule = require('../lib/rules/no-method-prefixed-with-on')
const RuleTester = require('eslint').RuleTester
const ruleTester = new RuleTester({env: {es2020: true}})
ruleTester.run('no-method-prefixed-with-on', rule, {
valid: [
{code: 'class FooBar extends HTMLElement { handleClick() { } }'},
{code: 'class FooBar extends HTMLElement { offClick() { } }'},
{code: 'class FooBar extends HTMLElement { click() { } }'},
{code: 'class FooBar extends HTMLElement { fooOnClick() { } }'},
{code: 'class FooBar extends HTMLElement { fooonclick() { } }'},
{code: 'class FooBar extends HTMLElement { handleOnClick() { } }'},
2022-11-30 20:54:48 +03:00
{code: 'class FooBar extends HTMLElement { handleonclick() { } }'},
],
invalid: [
{
code: 'class FooBar extends HTMLElement { onclick() { } }',
errors: [
{
message: 'Avoid method names prefixed with `on`',
2022-11-30 20:54:48 +03:00
type: 'MethodDefinition',
},
],
},
{
code: 'class FooBar extends HTMLElement { ontoggle() { } }',
errors: [
{
message: 'Avoid method names prefixed with `on`',
2022-11-30 20:54:48 +03:00
type: 'MethodDefinition',
},
],
},
{
code: 'class FooBar extends HTMLElement { onload() { } }',
errors: [
{
message: 'Avoid method names prefixed with `on`',
2022-11-30 20:54:48 +03:00
type: 'MethodDefinition',
},
],
},
{
code: 'class FooBar extends HTMLElement { onClick() { } }',
errors: [
{
message: 'Avoid method names prefixed with `on`',
2022-11-30 20:54:48 +03:00
type: 'MethodDefinition',
},
],
},
{
code: 'class FooBar extends HTMLElement { oncease() { } }',
errors: [
{
message: 'Avoid method names prefixed with `on`',
2022-11-30 20:54:48 +03:00
type: 'MethodDefinition',
},
],
},
],
})