|
| 1 | +/** |
| 2 | + * @author Toru Nagashima |
| 3 | + * @copyright 2017 Toru Nagashima. All rights reserved. |
| 4 | + * See LICENSE file in root directory for full license. |
| 5 | + */ |
| 6 | +'use strict' |
| 7 | + |
| 8 | +// ------------------------------------------------------------------------------ |
| 9 | +// Requirements |
| 10 | +// ------------------------------------------------------------------------------ |
| 11 | + |
| 12 | +const RuleTester = require('eslint').RuleTester |
| 13 | +const rule = require('../../../lib/rules/no-template-key') |
| 14 | + |
| 15 | +// ------------------------------------------------------------------------------ |
| 16 | +// Tests |
| 17 | +// ------------------------------------------------------------------------------ |
| 18 | + |
| 19 | +const tester = new RuleTester({ |
| 20 | + parser: 'vue-eslint-parser', |
| 21 | + parserOptions: { ecmaVersion: 2015 } |
| 22 | +}) |
| 23 | + |
| 24 | +tester.run('no-template-key', rule, { |
| 25 | + valid: [ |
| 26 | + { |
| 27 | + filename: 'test.vue', |
| 28 | + code: '' |
| 29 | + }, |
| 30 | + { |
| 31 | + filename: 'test.vue', |
| 32 | + code: '<template><template></template></template>' |
| 33 | + }, |
| 34 | + { |
| 35 | + filename: 'test.vue', |
| 36 | + code: '<template><div key="foo"></div></template>' |
| 37 | + }, |
| 38 | + { |
| 39 | + filename: 'test.vue', |
| 40 | + code: '<template><div v-bind:key="foo"></div></template>' |
| 41 | + }, |
| 42 | + { |
| 43 | + filename: 'test.vue', |
| 44 | + code: '<template><div :key="foo"></div></template>' |
| 45 | + } |
| 46 | + ], |
| 47 | + invalid: [ |
| 48 | + { |
| 49 | + filename: 'test.vue', |
| 50 | + code: '<template><div><template key="foo"></template></div></template>', |
| 51 | + errors: ["'<template>' cannot be keyed. Place the key on real elements instead."] |
| 52 | + }, |
| 53 | + { |
| 54 | + filename: 'test.vue', |
| 55 | + code: '<template><div><template v-bind:key="foo"></template></div></template>', |
| 56 | + errors: ["'<template>' cannot be keyed. Place the key on real elements instead."] |
| 57 | + }, |
| 58 | + { |
| 59 | + filename: 'test.vue', |
| 60 | + code: '<template><div><template :key="foo"></template></div></template>', |
| 61 | + errors: ["'<template>' cannot be keyed. Place the key on real elements instead."] |
| 62 | + } |
| 63 | + ] |
| 64 | +}) |
0 commit comments