22/**
33 * @jest -environment jsdom
44 */
5-
5+ import mutations from '../../../src/store/mutations' ;
66import { mount , createLocalVue , shallowMount } from '@vue/test-utils'
7+ import Vuex from 'vuex' ;
78import QBUTTON from './demo/QBtn-demo.vue'
89import * as All from 'quasar'
10+
911// import langEn from 'quasar/lang/en-us' // change to any language you wish! => this breaks wallaby :(
1012const { Quasar, date } = All
1113
14+ //const localVue = createLocalVue()
15+
16+ // localVue.use(Vuex)
17+
1218const components = Object . keys ( All ) . reduce ( ( object , key ) => {
1319 const val = All [ key ]
1420 if ( val && val . component && val . component . name != null ) {
1521 object [ key ] = val
1622 }
1723 return object
1824} , { } )
19-
20- describe ( 'Dummy test ' , ( ) => {
25+ /*
26+ describe('Mount Quasar ', () => {
2127 const localVue = createLocalVue()
22- localVue . use ( Quasar , { components } )
23- const testValue = false ;
24- it ( 'does this produce the correct result' , ( ) => {
25- expect ( testValue ) . toBe ( false )
26- } )
27- } )
28+ localVue.use(Quasar, { components }) // , lang: langEn
2829
29- describe ( 'Test Suite - Delete from userActions and/or componentMap' , ( ) => {
30- const localVue = createLocalVue ( )
31- localVue . use ( Quasar , { components } )
32- const testValue = false ;
33- it ( 'does this produce the correct result ahahaha' , ( ) => {
34- expect ( testValue ) . toBe ( false )
30+ const wrapper = mount(QBUTTON, {
31+ localVue
3532 })
36- } )
33+ const vm = wrapper.vm
3734
38- // describe('Mount Quasar ', () => {
39- // const localVue = createLocalVue( )
40- // localVue.use(Quasar, { components }) // , lang: langEn
35+ it('passes the sanity check and creates a wrapper ', () => {
36+ expect(wrapper.isVueInstance()).toBe(true )
37+ })
4138
42- // const wrapper = mount(QBUTTON, {
43- // localVue
44- // })
45- // const vm = wrapper.vm
39+ it('has a created hook', () => {
40+ expect(typeof vm.increment).toBe('function')
41+ })
4642
47- // it('passes the sanity check and creates a wrapper', () => {
48- // expect(wrapper.isVueInstance()).toBe(true)
49- // })
43+ it('accesses the shallowMount', () => {
44+ expect(vm.$el.textContent).toContain('rocket muffin')
45+ expect(wrapper.text()).toContain('rocket muffin') // easier
46+ expect(wrapper.find('p').text()).toContain('rocket muffin')
47+ })
5048
51- // it('has a created hook', () => {
52- // expect(typeof vm.increment).toBe('function')
53- // })
49+ it('sets the correct default data', () => {
50+ expect(typeof vm.counter).toBe('number')
51+ const defaultData2 = QBUTTON.data()
52+ expect(defaultData2.counter).toBe(0)
53+ })
5454
55- // it('accesses the shallowMount ', () => {
56- // expect(vm.$el.textContent).toContain('rocket muffin ')
57- // expect(wrapper.text()).toContain('rocket muffin') // easier
58- // expect(wrapper.find('p').text()).toContain('rocket muffin' )
59- // })
55+ it('correctly updates data when button is pressed ', () => {
56+ const button = wrapper.find('button ')
57+ button.trigger('click')
58+ expect(vm.counter).toBe(1 )
59+ })
6060
61- // it('sets the correct default data', () => {
62- // expect(typeof vm.counter).toBe('number')
63- // const defaultData2 = QBUTTON.data()
64- // expect(defaultData2.counter).toBe(0)
65- // })
61+ it('formats a date without throwing exception', () => {
62+ // test will automatically fail if an exception is thrown
63+ // MMMM and MMM require that a language is 'installed' in Quasar
64+ let formattedString = date.formatDate(Date.now(), 'YYYY MMMM MMM DD')
65+ console.log('formattedString', formattedString)
66+ })
67+ })
68+ */
69+ describe ( 'userActions mutation' , ( ) => {
70+ let actions ;
71+ let store ;
72+ beforeEach ( ( ) => {
73+ store = {
74+ userActions : [ ]
75+ }
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+ } ) ;
6686
67- // it('correctly updates data when button is pressed', () => {
68- // const button = wrapper.find('button')
69- // button.trigger('click')
70- // expect(vm.counter).toBe(1)
71- // })
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 )
109+ } )
72110
73- // it('formats a date without throwing exception', () => {
74- // // test will automatically fail if an exception is thrown
75- // // MMMM and MMM require that a language is 'installed' in Quasar
76- // let formattedString = date.formatDate(Date.now(), 'YYYY MMMM MMM DD')
77- // console.log('formattedString', formattedString)
78- // })
79- // })
111+ it ( 'should work with strings too' , ( ) => {
112+ mutations . ADD_TO_USER_STORE ( store , { string : 'string' } )
113+ expect ( store . userStore . string ) . toBe ( 'string' )
114+ } )
115+ } ) ;
0 commit comments