|
| 1 | +/** |
| 2 | + * @author Perry Song |
| 3 | + * @copyright 2023 Perry Song. All rights reserved. |
| 4 | + * See LICENSE file in root directory for full license. |
| 5 | + */ |
| 6 | +'use strict' |
| 7 | + |
| 8 | +const RuleTester = require('eslint').RuleTester |
| 9 | +const rule = require('../../../lib/rules/valid-v-if-template-root') |
| 10 | + |
| 11 | +const tester = new RuleTester({ |
| 12 | + parser: require.resolve('vue-eslint-parser'), |
| 13 | + parserOptions: { ecmaVersion: 2015 } |
| 14 | +}) |
| 15 | + |
| 16 | +tester.run('valid-v-if-template-root', rule, { |
| 17 | + valid: [ |
| 18 | + { |
| 19 | + filename: 'test.vue', |
| 20 | + code: '' |
| 21 | + }, |
| 22 | + { |
| 23 | + filename: 'test.vue', |
| 24 | + code: '<template><div>abc</div></template>' |
| 25 | + }, |
| 26 | + { |
| 27 | + filename: 'test.vue', |
| 28 | + code: '<template>\n <div>abc</div>\n</template>' |
| 29 | + }, |
| 30 | + { |
| 31 | + filename: 'test.vue', |
| 32 | + code: '<template>\n <!-- comment -->\n <div>abc</div>\n</template>' |
| 33 | + }, |
| 34 | + { |
| 35 | + filename: 'test.vue', |
| 36 | + code: '<template>\n <!-- comment -->\n <div v-if="foo">abc</div>\n <div v-else>abc</div>\n</template>' |
| 37 | + }, |
| 38 | + { |
| 39 | + filename: 'test.vue', |
| 40 | + code: '<template>\n <!-- comment -->\n <div v-if="foo">abc</div>\n <div v-else-if="bar">abc</div>\n <div v-else>abc</div>\n</template>' |
| 41 | + }, |
| 42 | + { |
| 43 | + filename: 'test.vue', |
| 44 | + code: `<template>\n <c1 v-if="1" />\n <c2 v-else-if="1" />\n <c3 v-else />\n</template>` |
| 45 | + }, |
| 46 | + { |
| 47 | + filename: 'test.vue', |
| 48 | + code: '<template><div v-if="foo"></div><div v-else-if="bar"></div></template>' |
| 49 | + }, |
| 50 | + { |
| 51 | + filename: 'test.vue', |
| 52 | + code: '<template src="foo.html"></template>' |
| 53 | + }, |
| 54 | + { |
| 55 | + filename: 'test.vue', |
| 56 | + code: '<template><div><textarea/>test</div></template>' |
| 57 | + }, |
| 58 | + { |
| 59 | + filename: 'test.vue', |
| 60 | + code: '<template><table><custom-thead></custom-thead></table></template>' |
| 61 | + }, |
| 62 | + { |
| 63 | + filename: 'test.vue', |
| 64 | + code: '<template><div></div><div></div></template>' |
| 65 | + }, |
| 66 | + { |
| 67 | + filename: 'test.vue', |
| 68 | + code: '<template>\n <div></div>\n <div></div>\n</template>' |
| 69 | + }, |
| 70 | + { |
| 71 | + filename: 'test.vue', |
| 72 | + code: '<template>{{a b c}}</template>' |
| 73 | + }, |
| 74 | + { |
| 75 | + filename: 'test.vue', |
| 76 | + code: '<template><div></div>aaaaaa</template>' |
| 77 | + }, |
| 78 | + { |
| 79 | + filename: 'test.vue', |
| 80 | + code: '<template>aaaaaa<div></div></template>' |
| 81 | + }, |
| 82 | + { |
| 83 | + filename: 'test.vue', |
| 84 | + code: '<template><div v-for="x in list"></div></template>' |
| 85 | + }, |
| 86 | + { |
| 87 | + filename: 'test.vue', |
| 88 | + code: '<template><slot></slot></template>' |
| 89 | + }, |
| 90 | + { |
| 91 | + filename: 'test.vue', |
| 92 | + code: '<template><template></template></template>' |
| 93 | + }, |
| 94 | + { |
| 95 | + filename: 'test.vue', |
| 96 | + code: '<template> <div v-if="mode === \'a\'"></div><div v-if="mode === \'b\'"></div></template>' |
| 97 | + } |
| 98 | + ], |
| 99 | + invalid: [ |
| 100 | + { |
| 101 | + filename: 'test.vue', |
| 102 | + code: '<template><custom-component v-if="foo"></custom-component></template>', |
| 103 | + errors: ['`v-if` should not be used on root element without `v-else`.'] |
| 104 | + }, |
| 105 | + { |
| 106 | + filename: 'test.vue', |
| 107 | + code: '<template><div v-if="foo"></div></template>', |
| 108 | + errors: ['`v-if` should not be used on root element without `v-else`.'] |
| 109 | + } |
| 110 | + ] |
| 111 | +}) |
0 commit comments