1
1
import { compileToFunctions } from 'vue-template-compiler'
2
- import { createLocalVue } from 'packages/test-utils/src'
2
+ import { createLocalVue , shallowMount } from 'packages/test-utils/src'
3
3
import Vue from 'vue'
4
+ import VueRouter from 'vue-router'
4
5
import ComponentWithChild from '~resources/components/component-with-child.vue'
5
6
import ComponentWithoutName from '~resources/components/component-without-name.vue'
6
7
import ComponentWithSlots from '~resources/components/component-with-slots.vue'
@@ -17,6 +18,58 @@ import {
17
18
import { itDoNotRunIf , itSkipIf } from 'conditional-specs'
18
19
19
20
describeWithShallowAndMount ( 'find' , mountingMethod => {
21
+ itDoNotRunIf (
22
+ mountingMethod . name === 'shallowMount' ,
23
+ 'returns a VueWrapper using a <router-view /> component' ,
24
+ async ( ) => {
25
+ const localVue = createLocalVue ( )
26
+ localVue . use ( VueRouter )
27
+ const TestComponentToFind = {
28
+ render : h => h ( 'div' ) ,
29
+ name : 'test-component-to-find'
30
+ }
31
+ const routes = [
32
+ {
33
+ path : '/a/b' ,
34
+ name : 'ab' ,
35
+ component : TestComponentToFind
36
+ }
37
+ ]
38
+ const router = new VueRouter ( { routes } )
39
+ const wrapper = mountingMethod (
40
+ {
41
+ template : '<router-view/>'
42
+ } ,
43
+ {
44
+ localVue,
45
+ router
46
+ }
47
+ )
48
+
49
+ await router . push ( '/a/b' )
50
+
51
+ expect ( wrapper . findComponent ( TestComponentToFind ) . exists ( ) ) . toBe ( true )
52
+ }
53
+ )
54
+
55
+ it ( 'findComponent in functional component' , ( ) => {
56
+ const Comp2 = {
57
+ name : 'test' ,
58
+ render ( h ) {
59
+ return h ( 'div' , 'test' )
60
+ }
61
+ }
62
+ const Comp = {
63
+ name : 'Comp' ,
64
+ functional : true ,
65
+ render ( h ) {
66
+ return h ( Comp2 )
67
+ }
68
+ }
69
+ const wrapper = shallowMount ( Comp )
70
+ wrapper . getComponent ( Comp2 )
71
+ } )
72
+
20
73
it ( 'returns a Wrapper matching tag selector passed' , ( ) => {
21
74
const compiled = compileToFunctions ( '<div><p></p><p></p></div>' )
22
75
const wrapper = mountingMethod ( compiled )
0 commit comments