|
| 1 | +/** |
| 2 | + * @author Niklas Higi |
| 3 | + */ |
| 4 | +'use strict' |
| 5 | + |
| 6 | +// ------------------------------------------------------------------------------ |
| 7 | +// Requirements |
| 8 | +// ------------------------------------------------------------------------------ |
| 9 | + |
| 10 | +const RuleTester = require('eslint').RuleTester |
| 11 | +const rule = require('../../../lib/rules/v-on-function-call') |
| 12 | + |
| 13 | +// ------------------------------------------------------------------------------ |
| 14 | +// Tests |
| 15 | +// ------------------------------------------------------------------------------ |
| 16 | + |
| 17 | +const tester = new RuleTester({ |
| 18 | + parser: 'vue-eslint-parser', |
| 19 | + parserOptions: { ecmaVersion: 2015 } |
| 20 | +}) |
| 21 | + |
| 22 | +tester.run('v-on-function-call', rule, { |
| 23 | + valid: [ |
| 24 | + { |
| 25 | + filename: 'test.vue', |
| 26 | + code: '' |
| 27 | + }, |
| 28 | + { |
| 29 | + filename: 'test.vue', |
| 30 | + code: '<template><div @click="foo(123)"></div></template>', |
| 31 | + options: ['always'] |
| 32 | + }, |
| 33 | + { |
| 34 | + filename: 'test.vue', |
| 35 | + code: '<template><div @click="foo(123)"></div></template>', |
| 36 | + options: ['never'] |
| 37 | + }, |
| 38 | + { |
| 39 | + filename: 'test.vue', |
| 40 | + code: '<template><div @click="foo()"></div></template>', |
| 41 | + options: ['always'] |
| 42 | + }, |
| 43 | + { |
| 44 | + filename: 'test.vue', |
| 45 | + code: '<template><div @click="foo"></div></template>', |
| 46 | + options: ['never'] |
| 47 | + } |
| 48 | + ], |
| 49 | + invalid: [ |
| 50 | + { |
| 51 | + filename: 'test.vue', |
| 52 | + code: '<template><div @click="foo"></div></template>', |
| 53 | + output: `<template><div @click="foo"></div></template>`, |
| 54 | + errors: ["Method calls inside of 'v-on' directives must have parentheses."], |
| 55 | + options: ['always'] |
| 56 | + }, |
| 57 | + { |
| 58 | + filename: 'test.vue', |
| 59 | + code: '<template><div @click="foo()"></div></template>', |
| 60 | + output: `<template><div @click="foo"></div></template>`, |
| 61 | + errors: ["Method calls without arguments inside of 'v-on' directives must not have parentheses."], |
| 62 | + options: ['never'] |
| 63 | + }, |
| 64 | + { |
| 65 | + filename: 'test.vue', |
| 66 | + code: '<template><div @click="foo( )"></div></template>', |
| 67 | + output: `<template><div @click="foo"></div></template>`, |
| 68 | + errors: ["Method calls without arguments inside of 'v-on' directives must not have parentheses."], |
| 69 | + options: ['never'] |
| 70 | + } |
| 71 | + ] |
| 72 | +}) |
0 commit comments