|
| 1 | +const rule = require('../../../lib/rules/template-no-action-modifiers'); |
| 2 | +const RuleTester = require('eslint').RuleTester; |
| 3 | + |
| 4 | +const ruleTester = new RuleTester({ |
| 5 | + parser: require.resolve('ember-eslint-parser'), |
| 6 | + parserOptions: { ecmaVersion: 2022, sourceType: 'module' }, |
| 7 | +}); |
| 8 | + |
| 9 | +ruleTester.run('template-no-action-modifiers', rule, { |
| 10 | + valid: [ |
| 11 | + '<template><button {{on "click" this.handleClick}}>Click</button></template>', |
| 12 | + '<template><div {{on "mouseenter" this.onHover}}>Hover</div></template>', |
| 13 | + '<template><form {{on "submit" this.handleSubmit}}>Submit</form></template>', |
| 14 | + '<template>{{action "myAction"}}</template>', |
| 15 | + '<template>{{this.action}}</template>', |
| 16 | + '<template>{{@action}}</template>', |
| 17 | + ], |
| 18 | + |
| 19 | + invalid: [ |
| 20 | + { |
| 21 | + code: '<template><button {{action "save"}}>Save</button></template>', |
| 22 | + output: null, |
| 23 | + errors: [ |
| 24 | + { |
| 25 | + message: 'Do not use action modifiers. Use on modifier with a function instead.', |
| 26 | + type: 'GlimmerElementModifierStatement', |
| 27 | + }, |
| 28 | + ], |
| 29 | + }, |
| 30 | + { |
| 31 | + code: '<template><div {{action "onClick"}}>Click me</div></template>', |
| 32 | + output: null, |
| 33 | + errors: [ |
| 34 | + { |
| 35 | + message: 'Do not use action modifiers. Use on modifier with a function instead.', |
| 36 | + type: 'GlimmerElementModifierStatement', |
| 37 | + }, |
| 38 | + ], |
| 39 | + }, |
| 40 | + { |
| 41 | + code: '<template><form {{action "submit" on="submit"}}>Submit</form></template>', |
| 42 | + output: null, |
| 43 | + errors: [ |
| 44 | + { |
| 45 | + message: 'Do not use action modifiers. Use on modifier with a function instead.', |
| 46 | + type: 'GlimmerElementModifierStatement', |
| 47 | + }, |
| 48 | + ], |
| 49 | + }, |
| 50 | + ], |
| 51 | +}); |
0 commit comments