2
2
/**
3
3
* @jest -environment jsdom
4
4
*/
5
- import actions from '../../store/actions ' ;
5
+ import mutations from '../../../src/ store/mutations ' ;
6
6
import { mount , createLocalVue , shallowMount } from '@vue/test-utils'
7
+ import Vuex from 'vuex' ;
7
8
import QBUTTON from './demo/QBtn-demo.vue'
8
9
import * as All from 'quasar'
10
+
9
11
// import langEn from 'quasar/lang/en-us' // change to any language you wish! => this breaks wallaby :(
10
12
const { Quasar, date } = All
11
13
12
- const localVue = createLocalVue ( )
14
+ // const localVue = createLocalVue()
13
15
14
- localVue . use ( Vuex )
16
+ // localVue.use(Vuex)
15
17
16
18
const components = Object . keys ( All ) . reduce ( ( object , key ) => {
17
19
const val = All [ key ]
@@ -64,23 +66,50 @@ describe('Mount Quasar', () => {
64
66
})
65
67
})
66
68
*/
67
- describe ( 'actions ' , ( ) => {
69
+ describe ( 'userActions mutation ' , ( ) => {
68
70
let actions ;
69
71
let store ;
70
72
beforeEach ( ( ) => {
71
- const dummyFunction = jest . fn ( ( ) => 'hello' )
72
- actions = {
73
- userActionInput : dummyFunction ,
74
- userStore : dummyFunction
73
+ store = {
74
+ userActions : [ ]
75
75
}
76
- store = new Vuex . Store ( {
77
- actions
78
- } )
79
76
} )
77
+ it ( 'should push user defined action to end of userActions array' , ( ) => {
78
+ mutations . ADD_USER_ACTION ( store , 'actionnnn' )
79
+ expect ( store . userActions [ store . userActions . length - 1 ] ) . toBe ( 'actionnnn' ) ;
80
+ } )
81
+ it ( 'should only push to array if payload is of type string' , ( ) => {
82
+ mutations . ADD_USER_ACTION ( store , 66 )
83
+ expect ( store . userActions ) . toStrictEqual ( [ ] )
84
+ } )
85
+ } ) ;
80
86
81
- it ( 'should take in a string and output a string into userActions array' , ( ) => {
82
- const wrapper = shallowMount ( actions , { store, localVue } )
83
-
87
+ describe ( 'userStore mutation' , ( ) => {
88
+ let actions ;
89
+ let store ;
90
+ store = {
91
+ userStore : { }
92
+ }
93
+ it ( 'should be able to update store with a key defined by the user and a value of type object' , ( ) => {
94
+ mutations . ADD_TO_USER_STORE ( store , { 'dummyKey' : { } } )
95
+ // console.log('store.userStore.dummyKey', store.userStore.dummyKey);
96
+ expect ( store . userStore . dummyKey ) . toStrictEqual ( { } )
97
+ } )
98
+ it ( 'should update user store with a key value pair with value strictly equal to empty array' , ( ) => {
99
+ mutations . ADD_TO_USER_STORE ( store , { 'dummyKey' : [ ] } )
100
+ expect ( store . userStore . dummyKey ) . toStrictEqual ( [ ] ) ;
101
+ } )
102
+ it ( 'should be able to store booleans in the store as the key' , ( ) => {
103
+ mutations . ADD_TO_USER_STORE ( store , { boolean : true } )
104
+ expect ( store . userStore . boolean ) . toBe ( true )
105
+ } )
106
+ it ( 'should add to userStore a key with a value of type number' , ( ) => {
107
+ mutations . ADD_TO_USER_STORE ( store , { number :696 } )
108
+ expect ( store . userStore . number ) . toBe ( 696 )
84
109
} )
85
110
111
+ it ( 'should work with strings too' , ( ) => {
112
+ mutations . ADD_TO_USER_STORE ( store , { string : 'string' } )
113
+ expect ( store . userStore . string ) . toBe ( 'string' )
114
+ } )
86
115
} ) ;
0 commit comments