forked from UnrefinedBrain/vue-upgrade-tool
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglobal-mount-options.spec.ts
More file actions
131 lines (113 loc) · 2.92 KB
/
global-mount-options.spec.ts
File metadata and controls
131 lines (113 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import { expect, it } from 'vitest';
import { transform } from 'vue-metamorph';
import { globalMountOptionsPlugin } from './global-mount-options';
it('should construct a new global object in mount options', () => {
const input = `
// should remove the createLocalVue import
import { shallowMount, createLocalVue } from '@vue/test-utils';
// should remove createLocalVue call and localVue.* calls
const localVue = createLocalVue();
localVue.mixin({
data() {
return {
foo: 'bar'
}
}
});
localVue.directive('asdf', {
// directive body
});
localVue.component('MyButton', MyButton);
it('test', () => {
// should remove the localVue option
// should move store,router,i18n into global.plugins
// should move mocks to global.mocks
// should move stubs to global.stubs
// should move localVue.directive() to global.directives
// should move localVue.component() to global.components
// should move localVue.mixin() to global.mixins
shallowMount(SomeComponent, {
localVue,
store,
router,
i18n,
mocks: {
// some mocks
},
stubs: {
// some stubs
}
});
});
`;
expect(transform(input, 'file.spec.js', [globalMountOptionsPlugin]).code).toMatchInlineSnapshot(`
"// should remove the createLocalVue import
import { shallowMount } from '@vue/test-utils';
it('test', () => {
// should remove the localVue option
// should move store,router,i18n into global.plugins
// should move mocks to global.mocks
// should move stubs to global.stubs
// should move localVue.directive() to global.directives
// should move localVue.component() to global.components
// should move localVue.mixin() to global.mixins
shallowMount(SomeComponent, {
global: {
mixins: [{
data() {
return {
foo: 'bar'
}
}
}],
directives: {
'asdf': {
// directive body
},
},
components: {
'MyButton': MyButton,
},
plugins: [store, router, i18n],
mocks: {
// some mocks
},
stubs: {
// some stubs
},
},
});
});
"
`);
});
it('should not duplicate existing mount options objects', () => {
const input = `
mount(Component, {
global: {
mocks: {
}
}
});
`;
expect(transform(input, 'file.spec.js', [globalMountOptionsPlugin]).code).toMatchInlineSnapshot(`
"mount(Component, {
global: {
mocks: {
}
}
});
"
`);
});
it('should not remove localVue calls that are not feeding the global property', () => {
const input = `
localVue.nextTick();
await localVue.nextTick();
`;
expect(transform(input, 'file.spec.js', [globalMountOptionsPlugin]).code).toMatchInlineSnapshot(`
"localVue.nextTick();
await localVue.nextTick();
"
`);
});