1
- import { shallowMount , createLocalVue } from '@vue/test-utils'
2
- import { $routerMocks , RouterLink } from '../utils'
1
+ import { mount , createLocalVue } from '@vue/test-utils'
2
+ import { $routerMocks , EVENT_DATA , RouterLink } from '../utils'
3
3
import EventHeader from '@/components/event/Header'
4
4
import BootstrapVue from 'bootstrap-vue'
5
5
import Event from '@/components/Event'
6
6
import $moment from 'moment'
7
- import $http from 'axios '
7
+ import flushPromises from 'flush-promises '
8
8
9
9
const localVue = createLocalVue ( )
10
10
localVue . use ( BootstrapVue )
11
11
12
- describe ( 'Event.vue' , ( ) => {
13
-
12
+ function createWrapper ( $http )
13
+ {
14
14
const $store = {
15
15
getters : {
16
16
user : {
@@ -19,7 +19,7 @@ describe('Event.vue', () => {
19
19
}
20
20
}
21
21
22
- const wrapper = shallowMount ( Event , {
22
+ return mount ( Event , {
23
23
mocks : Object . assign ( { $http, $moment, $store } , $routerMocks ) ,
24
24
stubs : { RouterLink } ,
25
25
propsData : {
@@ -29,9 +29,63 @@ describe('Event.vue', () => {
29
29
} ,
30
30
localVue
31
31
} )
32
+ }
33
+
34
+ const resp = {
35
+ data : {
36
+ data : EVENT_DATA
37
+ }
38
+ }
39
+
40
+ describe ( 'Event.vue' , ( ) => {
41
+
42
+ describe ( 'Request Event' , ( ) => {
43
+
44
+ ( [
45
+
46
+ [ 'Response Success if user authenticated' , ( ) => Promise . resolve ( resp ) , wrapper => {
47
+
48
+ wrapper . vm . $store . getters . user . authenticated = true
49
+
50
+ flushPromises ( ) . then ( ( ) => {
51
+ expect ( wrapper . vm . event . id ) . to . eql ( EVENT_DATA . id )
52
+ } )
53
+
54
+ } ] ,
55
+
56
+ [ 'Response Success if not user authenticated' , ( ) => Promise . resolve ( resp ) , wrapper => {
57
+ flushPromises ( ) . then ( ( ) => {
58
+ expect ( wrapper . vm . event . id ) . to . eql ( EVENT_DATA . id )
59
+ } )
60
+ } ] ,
61
+
62
+ [ 'Response Error' , ( ) => Promise . reject ( {
63
+ response : {
64
+ statusText : '' ,
65
+ status : 403
66
+ }
67
+ } ) , wrapper => {
68
+ flushPromises ( ) . then ( ( ) => {
69
+ expect ( wrapper . vm . errorResponse . status ) . to . eql ( 403 )
70
+ } )
71
+ } ]
72
+
73
+ ] ) . forEach ( conf => {
74
+
75
+ const [ label , httpResp , callBack ] = conf
76
+
77
+ const wrapper = createWrapper ( {
78
+ get : httpResp
79
+ } )
80
+
81
+ it ( label , async ( ) => {
82
+ callBack ( wrapper )
83
+ } )
84
+
85
+ wrapper . destroy ( )
86
+
87
+ } )
32
88
33
- it ( 'Check component Event' , ( ) => {
34
- expect ( wrapper . is ( Event ) ) . to . eql ( true )
35
89
} )
36
90
37
91
} )
0 commit comments