mirror of
https://github.com/IT4Change/gradido.git
synced 2026-04-06 01:25:28 +00:00
try to test App
This commit is contained in:
parent
d889df51fe
commit
b15b509e5e
67
admin/src/App.spec.js
Normal file
67
admin/src/App.spec.js
Normal file
@ -0,0 +1,67 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import App from './App'
|
||||
|
||||
const localVue = global.localVue
|
||||
|
||||
const storeCommitMock = jest.fn()
|
||||
|
||||
const mocks = {
|
||||
$store: {
|
||||
commit: storeCommitMock,
|
||||
},
|
||||
}
|
||||
|
||||
const storageMock = () => {
|
||||
let storage = {}
|
||||
|
||||
return {
|
||||
setItem: function(key, value) {
|
||||
console.log('SET CALLED')
|
||||
storage[key] = value || ''
|
||||
},
|
||||
getItem: function(key) {
|
||||
console.log('GET CALLED')
|
||||
return key in storage ? storage[key] : null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// window.localStorage = storageMock()
|
||||
|
||||
describe('App', () => {
|
||||
let wrapper
|
||||
|
||||
const Wrapper = () => {
|
||||
return mount(App, { localVue, mocks })
|
||||
}
|
||||
|
||||
describe('mount', () => {
|
||||
beforeEach(() => {
|
||||
wrapper = Wrapper()
|
||||
})
|
||||
|
||||
it('has a div with id "app"', () => {
|
||||
expect(wrapper.find('div#app').exists()).toBeTruthy()
|
||||
})
|
||||
})
|
||||
|
||||
describe('window localStorage is undefined', () => {
|
||||
it('does not commit a token to the store', () => {
|
||||
expect(storeCommitMock).not.toBeCalled()
|
||||
})
|
||||
})
|
||||
|
||||
describe('with token in local storage', () => {
|
||||
beforeEach(() => {
|
||||
console.log('Test', window.localStorage)
|
||||
window.localStorage = { 'foo': 'bar' }
|
||||
console.log('Test', window.localStorage)
|
||||
//window.localStorage.setItem('vuex', { token: 1234 })
|
||||
})
|
||||
|
||||
it('commits the token to the store', () => {
|
||||
expect(storeCommitMock).toBeCalledWith('token', 1234)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@ -3,17 +3,18 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'App',
|
||||
methods: {
|
||||
async readToken() {
|
||||
if (window.localStorage && window.localStorage.vuex) {
|
||||
this.$store.commit('token', JSON.parse(window.localStorage.vuex).token)
|
||||
}
|
||||
},
|
||||
},
|
||||
created() {
|
||||
this.readToken()
|
||||
},
|
||||
}
|
||||
export default {
|
||||
name: 'App',
|
||||
methods: {
|
||||
async readToken() {
|
||||
console.log('App', window.localStorage, window.localStorage.getItem('vuex'))
|
||||
if (window.localStorage && window.localStorage.vuex) {
|
||||
this.$store.commit('token', JSON.parse(window.localStorage.vuex).token)
|
||||
}
|
||||
},
|
||||
},
|
||||
created() {
|
||||
this.readToken()
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
@ -2,6 +2,9 @@ import { createLocalVue } from '@vue/test-utils'
|
||||
import Vue from 'vue'
|
||||
import { BootstrapVue } from 'bootstrap-vue'
|
||||
|
||||
// without this async calls are not working
|
||||
import 'regenerator-runtime'
|
||||
|
||||
global.localVue = createLocalVue()
|
||||
|
||||
global.localVue.use(BootstrapVue)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user