mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
coverage password-reset.spec.js
This commit is contained in:
parent
5ffad4056b
commit
c6fd705748
@ -1,3 +1,4 @@
|
|||||||
|
import Vuex from 'vuex'
|
||||||
import { config, mount } from '@vue/test-utils'
|
import { config, mount } from '@vue/test-utils'
|
||||||
import PasswordReset from './password-reset.vue'
|
import PasswordReset from './password-reset.vue'
|
||||||
|
|
||||||
@ -9,6 +10,11 @@ config.stubs['nuxt-child'] = '<span class="nuxt-child"><slot /></span>'
|
|||||||
describe('password-reset.vue', () => {
|
describe('password-reset.vue', () => {
|
||||||
let wrapper
|
let wrapper
|
||||||
let mocks
|
let mocks
|
||||||
|
let asyncData
|
||||||
|
let store
|
||||||
|
let redirect
|
||||||
|
let isLoggedIn
|
||||||
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
mocks = {
|
mocks = {
|
||||||
@ -17,22 +23,50 @@ describe('password-reset.vue', () => {
|
|||||||
locale: () => 'en',
|
locale: () => 'en',
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
asyncData = false
|
||||||
|
isLoggedIn = false
|
||||||
|
redirect = jest.fn()
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('mount', () => {
|
describe('mount', () => {
|
||||||
const Wrapper = () => {
|
const Wrapper = async () => {
|
||||||
|
store = new Vuex.Store({
|
||||||
|
getters: {
|
||||||
|
'auth/isLoggedIn': () => isLoggedIn,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
if (asyncData) {
|
||||||
|
const data = PasswordReset.data ? PasswordReset.data() : {}
|
||||||
|
const aData = await PasswordReset.asyncData({
|
||||||
|
store,
|
||||||
|
redirect
|
||||||
|
})
|
||||||
|
PasswordReset.data = function() {
|
||||||
|
return { ...data, ...aData};
|
||||||
|
};
|
||||||
|
}
|
||||||
return mount(PasswordReset, {
|
return mount(PasswordReset, {
|
||||||
mocks,
|
mocks,
|
||||||
localVue,
|
localVue,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
beforeEach(() => {
|
it('renders', async () => {
|
||||||
wrapper = Wrapper()
|
wrapper = await Wrapper()
|
||||||
|
expect(wrapper.is('div')).toBe(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('renders', () => {
|
it('renders with asyncData and not loggedIn', async () => {
|
||||||
expect(wrapper.is('div')).toBe(true)
|
asyncData = true
|
||||||
|
wrapper = await Wrapper()
|
||||||
|
expect(redirect).not.toHaveBeenCalled()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('renders with asyncData and loggedIn', async () => {
|
||||||
|
asyncData = true
|
||||||
|
isLoggedIn = true
|
||||||
|
wrapper = await Wrapper()
|
||||||
|
expect(redirect).toBeCalledWith('/')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user