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'
9- import mutations from '../../../src/store/mutations'
1010// import langEn from 'quasar/lang/en-us' // change to any language you wish! => this breaks wallaby :(
1111const { Quasar, date } = All
1212
13+ //const localVue = createLocalVue()
14+
15+ // localVue.use(Vuex)
16+
1317const components = Object . keys ( All ) . reduce ( ( object , key ) => {
1418 const val = All [ key ]
1519 if ( val && val . component && val . component . name != null ) {
@@ -18,15 +22,6 @@ const components = Object.keys(All).reduce((object, key) => {
1822 return object
1923} , { } )
2024
21- describe ( 'Dummy test' , ( ) => {
22- const localVue = createLocalVue ( )
23- localVue . use ( Quasar , { components } )
24- const testValue = false ;
25- it ( 'does this produce the correct result' , ( ) => {
26- expect ( testValue ) . toBe ( false )
27- } )
28- } )
29-
3025describe ( 'Adding actions and state to components' , ( ) => {
3126 let state ;
3227 beforeEach ( ( ) => {
@@ -57,45 +52,50 @@ describe('Adding actions and state to components', () => {
5752 } )
5853} )
5954
60- // describe('Mount Quasar', () => {
61- // const localVue = createLocalVue()
62- // localVue.use(Quasar, { components }) // , lang: langEn
63-
64- // const wrapper = mount(QBUTTON, {
65- // localVue
66- // })
67- // const vm = wrapper.vm
68-
69- // it('passes the sanity check and creates a wrapper', () => {
70- // expect(wrapper.isVueInstance()).toBe(true)
71- // })
72-
73- // it('has a created hook', () => {
74- // expect(typeof vm.increment).toBe('function')
75- // })
76-
77- // it('accesses the shallowMount', () => {
78- // expect(vm.$el.textContent).toContain('rocket muffin')
79- // expect(wrapper.text()).toContain('rocket muffin') // easier
80- // expect(wrapper.find('p').text()).toContain('rocket muffin')
81- // })
82-
83- // it('sets the correct default data', () => {
84- // expect(typeof vm.counter).toBe('number')
85- // const defaultData2 = QBUTTON.data()
86- // expect(defaultData2.counter).toBe(0)
87- // })
55+ describe ( 'userActions mutation' , ( ) => {
56+ let actions ;
57+ let store ;
58+ beforeEach ( ( ) => {
59+ store = {
60+ userActions : [ ]
61+ }
62+ } )
63+ it ( 'should push user defined action to end of userActions array' , ( ) => {
64+ mutations . ADD_USER_ACTION ( store , 'actionnnn' )
65+ expect ( store . userActions [ store . userActions . length - 1 ] ) . toBe ( 'actionnnn' ) ;
66+ } )
67+ it ( 'should only push to array if payload is of type string' , ( ) => {
68+ mutations . ADD_USER_ACTION ( store , 66 )
69+ expect ( store . userActions ) . toStrictEqual ( [ ] )
70+ } )
71+ } ) ;
8872
89- // it('correctly updates data when button is pressed', () => {
90- // const button = wrapper.find('button')
91- // button.trigger('click')
92- // expect(vm.counter).toBe(1)
93- // })
73+ describe ( 'userStore mutation' , ( ) => {
74+ let actions ;
75+ let store ;
76+ store = {
77+ userStore : { }
78+ }
79+ it ( 'should be able to update store with a key defined by the user and a value of type object' , ( ) => {
80+ mutations . ADD_TO_USER_STORE ( store , { 'dummyKey' : { } } )
81+ // console.log('store.userStore.dummyKey', store.userStore.dummyKey);
82+ expect ( store . userStore . dummyKey ) . toStrictEqual ( { } )
83+ } )
84+ it ( 'should update user store with a key value pair with value strictly equal to empty array' , ( ) => {
85+ mutations . ADD_TO_USER_STORE ( store , { 'dummyKey' : [ ] } )
86+ expect ( store . userStore . dummyKey ) . toStrictEqual ( [ ] ) ;
87+ } )
88+ it ( 'should be able to store booleans in the store as the key' , ( ) => {
89+ mutations . ADD_TO_USER_STORE ( store , { boolean : true } )
90+ expect ( store . userStore . boolean ) . toBe ( true )
91+ } )
92+ it ( 'should add to userStore a key with a value of type number' , ( ) => {
93+ mutations . ADD_TO_USER_STORE ( store , { number :696 } )
94+ expect ( store . userStore . number ) . toBe ( 696 )
95+ } )
9496
95- // it('formats a date without throwing exception', () => {
96- // // test will automatically fail if an exception is thrown
97- // // MMMM and MMM require that a language is 'installed' in Quasar
98- // let formattedString = date.formatDate(Date.now(), 'YYYY MMMM MMM DD')
99- // console.log('formattedString', formattedString)
100- // })
101- // })
97+ it ( 'should work with strings too' , ( ) => {
98+ mutations . ADD_TO_USER_STORE ( store , { string : 'string' } )
99+ expect ( store . userStore . string ) . toBe ( 'string' )
100+ } )
101+ } ) ;
0 commit comments