@@ -4,11 +4,13 @@ import { mount, createLocalVue } from '~vue/test-utils'
4
4
import Component from '~resources/components/component.vue'
5
5
import ComponentWithProps from '~resources/components/component-with-props.vue'
6
6
import ComponentWithMixin from '~resources/components/component-with-mixin.vue'
7
+ import ComponentAsAClass from '~resources/components/component-as-a-class.vue'
7
8
import { injectSupported , vueVersion } from '~resources/utils'
8
9
import {
9
10
describeRunIf ,
10
11
itDoNotRunIf
11
12
} from 'conditional-specs'
13
+ import Vuex from 'vuex'
12
14
13
15
describeRunIf ( process . env . TEST_ENV !== 'node' ,
14
16
'mount' , ( ) => {
@@ -62,7 +64,12 @@ describeRunIf(process.env.TEST_ENV !== 'node',
62
64
63
65
it ( 'returns new VueWrapper with mounted Vue instance initialized with Vue.extend with props, if passed as propsData' , ( ) => {
64
66
const prop1 = { test : 'TEST' }
65
- const wrapper = mount ( Vue . extend ( ComponentWithProps ) , { propsData : { prop1 } } )
67
+ const TestComponent = Vue . extend ( ComponentWithProps )
68
+ const wrapper = mount ( TestComponent , {
69
+ propsData : {
70
+ prop1
71
+ }
72
+ } )
66
73
expect ( wrapper . vm ) . to . be . an ( 'object' )
67
74
if ( wrapper . vm . $props ) {
68
75
expect ( wrapper . vm . $props . prop1 ) . to . equal ( prop1 )
@@ -131,6 +138,25 @@ describeRunIf(process.env.TEST_ENV !== 'node',
131
138
expect ( wrapper . html ( ) ) . to . equal ( `<div>foo</div>` )
132
139
} )
133
140
141
+ it ( 'overrides methods' , ( ) => {
142
+ const stub = sinon . stub ( )
143
+ const TestComponent = Vue . extend ( {
144
+ template : '<div />' ,
145
+ methods : {
146
+ callStub ( ) {
147
+ stub ( )
148
+ }
149
+ }
150
+ } )
151
+ mount ( TestComponent , {
152
+ methods : {
153
+ callStub ( ) { }
154
+ }
155
+ } ) . vm . callStub ( )
156
+
157
+ expect ( stub ) . not . called
158
+ } )
159
+
134
160
// Problems accessing options of twice extended components in Vue < 2.3
135
161
itDoNotRunIf ( vueVersion < 2.3 ,
136
162
'compiles extended components' , ( ) => {
@@ -195,6 +221,20 @@ describeRunIf(process.env.TEST_ENV !== 'node',
195
221
expect ( wrapper . vm . $options . listeners ) . to . equal ( undefined )
196
222
} )
197
223
224
+ it ( 'injects store correctly' , ( ) => {
225
+ const localVue = createLocalVue ( )
226
+ localVue . use ( Vuex )
227
+ const store = new Vuex . Store ( )
228
+ const wrapper = mount ( ComponentAsAClass , {
229
+ store,
230
+ localVue
231
+ } )
232
+ wrapper . vm . getters
233
+ mount ( {
234
+ template : '<div>{{$store.getters}}</div>'
235
+ } , { store, localVue } )
236
+ } )
237
+
198
238
it ( 'propagates errors when they are thrown' , ( ) => {
199
239
const TestComponent = {
200
240
template : '<div></div>' ,
@@ -261,7 +301,7 @@ describeRunIf(process.env.TEST_ENV !== 'node',
261
301
Vue . config . errorHandler = null
262
302
} )
263
303
264
- it ( 'overwrites the component options with the options other than the mounting options when the options for mount contain those ' , ( ) => {
304
+ it ( 'overwrites the component options with the instance options' , ( ) => {
265
305
const Component = {
266
306
template : '<div>{{ foo() }}{{ bar() }}{{ baz() }}</div>' ,
267
307
methods : {
0 commit comments