|
| 1 | +const generateWithPlugin = require('@vue/cli-test-utils/generateWithPlugin') |
| 2 | + |
| 3 | +test('base', async () => { |
| 4 | + const { files, pkg } = await generateWithPlugin({ |
| 5 | + id: 'router', |
| 6 | + apply: require('../generator'), |
| 7 | + options: {} |
| 8 | + }) |
| 9 | + |
| 10 | + expect(files['src/router/index.js']).toBeTruthy() |
| 11 | + expect(files['src/router/index.js']).not.toMatch('history') |
| 12 | + expect(files['src/views/About.vue']).toBeTruthy() |
| 13 | + expect(files['src/views/Home.vue']).toBeTruthy() |
| 14 | + expect(files['src/App.vue']).toMatch('<router-link to="/">Home</router-link>') |
| 15 | + expect(files['src/App.vue']).not.toMatch('<script>') |
| 16 | + expect(files['src/App.vue']).toMatch('#nav a.router-link-exact-active') |
| 17 | + |
| 18 | + expect(pkg.dependencies).toHaveProperty('vue-router') |
| 19 | +}) |
| 20 | + |
| 21 | +test('history mode', async () => { |
| 22 | + const { files, pkg } = await generateWithPlugin({ |
| 23 | + id: 'router', |
| 24 | + apply: require('../generator'), |
| 25 | + options: { |
| 26 | + historyMode: true |
| 27 | + } |
| 28 | + }) |
| 29 | + |
| 30 | + expect(files['src/router/index.js']).toBeTruthy() |
| 31 | + expect(files['src/router/index.js']).toMatch('history') |
| 32 | + expect(files['src/views/About.vue']).toBeTruthy() |
| 33 | + expect(files['src/views/Home.vue']).toBeTruthy() |
| 34 | + expect(files['src/App.vue']).toMatch('<router-link to="/">Home</router-link>') |
| 35 | + expect(files['src/App.vue']).not.toMatch('<script>') |
| 36 | + expect(files['src/App.vue']).toMatch('#nav a.router-link-exact-active') |
| 37 | + |
| 38 | + expect(pkg.dependencies).toHaveProperty('vue-router') |
| 39 | +}) |
| 40 | + |
| 41 | +test('use with Babel', async () => { |
| 42 | + const { pkg, files } = await generateWithPlugin([ |
| 43 | + { |
| 44 | + id: 'babel', |
| 45 | + apply: require('@vue/cli-plugin-babel/generator'), |
| 46 | + options: {} |
| 47 | + }, |
| 48 | + { |
| 49 | + id: 'router', |
| 50 | + apply: require('../generator'), |
| 51 | + options: {} |
| 52 | + } |
| 53 | + ]) |
| 54 | + |
| 55 | + expect(files['src/router/index.js']).toBeTruthy() |
| 56 | + expect(files['src/router/index.js']).toMatch('component: () => import') |
| 57 | + expect(files['src/views/About.vue']).toBeTruthy() |
| 58 | + expect(files['src/views/Home.vue']).toBeTruthy() |
| 59 | + expect(files['src/App.vue']).toMatch('<router-link to="/">Home</router-link>') |
| 60 | + expect(files['src/App.vue']).not.toMatch('<script>') |
| 61 | + expect(files['src/App.vue']).toMatch('#nav a.router-link-exact-active') |
| 62 | + |
| 63 | + expect(pkg.dependencies).toHaveProperty('vue-router') |
| 64 | +}) |
0 commit comments