File tree 3 files changed +45
-3
lines changed
3 files changed +45
-3
lines changed Original file line number Diff line number Diff line change @@ -16,12 +16,29 @@ function getStubs (optionStubs, config) {
16
16
}
17
17
}
18
18
19
+ function getMocks ( optionMocks , config ) {
20
+ if ( optionMocks ||
21
+ ( config . mocks && Object . keys ( config . mocks ) . length > 0 ) ) {
22
+ if ( Array . isArray ( optionMocks ) ) {
23
+ return [
24
+ ...optionMocks ,
25
+ ...Object . keys ( config . mocks || { } ) ]
26
+ } else {
27
+ return {
28
+ ...config . mocks ,
29
+ ...optionMocks
30
+ }
31
+ }
32
+ }
33
+ }
34
+
19
35
export function mergeOptions (
20
36
options : Options ,
21
37
config : Options
22
38
) : Options {
23
39
return {
24
40
...options ,
25
- stubs : getStubs ( options . stubs , config )
41
+ stubs : getStubs ( options . stubs , config ) ,
42
+ mocks : getMocks ( options . mocks , config )
26
43
}
27
44
}
Original file line number Diff line number Diff line change @@ -5,5 +5,6 @@ export default {
5
5
stubs : {
6
6
transition : TransitionStub ,
7
7
'transition-group' : TransitionGroupStub
8
- }
8
+ } ,
9
+ mocks : { }
9
10
}
Original file line number Diff line number Diff line change 2
2
mount ,
3
3
config ,
4
4
TransitionStub ,
5
- TransitionGroupStub
5
+ TransitionGroupStub ,
6
+ createLocalVue
6
7
} from '~vue/test-utils'
7
8
8
9
describe ( 'config' , ( ) => {
@@ -33,6 +34,29 @@ describe('config', () => {
33
34
expect ( wrapper . contains ( TransitionGroupStub ) ) . to . equal ( true )
34
35
} )
35
36
37
+ it ( 'mocks a global variable' , ( ) => {
38
+ const localVue = createLocalVue ( )
39
+ const t = 'real value'
40
+ localVue . prototype . $t = t
41
+
42
+ const testComponent = {
43
+ template : `
44
+ <div>{{ $t }}</div>
45
+ `
46
+ }
47
+
48
+ config . mocks [ '$t' ] = 'mock value'
49
+
50
+ const wrapper = mount ( testComponent , {
51
+ localVue, t
52
+ } )
53
+
54
+ expect ( wrapper . vm . $t ) . to . equal ( 'mock value' )
55
+ expect ( wrapper . text ( ) ) . to . equal ( 'mock value' )
56
+
57
+ localVue . prototype . $t = undefined
58
+ } )
59
+
36
60
it ( 'doesn\'t stub transition when config.stubs.transition is set to false' , ( ) => {
37
61
const testComponent = {
38
62
template : `
You can’t perform that action at this time.
0 commit comments