first pages test working

This commit is contained in:
Moriz Wahl 2023-02-13 20:29:16 +01:00
parent 6aead3f75e
commit b2be8a301e
4 changed files with 32 additions and 23 deletions

View File

@ -1,7 +1,9 @@
import { config, mount } from '@vue/test-utils' import { mount } from '@vue/test-utils'
import admin from './admin.vue' import admin from './admin.vue'
config.stubs['nuxt-child'] = '<span><slot /></span>' const stubs = {
'nuxt-child': true,
}
const localVue = global.localVue const localVue = global.localVue
@ -20,6 +22,7 @@ describe('admin.vue', () => {
return mount(admin, { return mount(admin, {
mocks, mocks,
localVue, localVue,
stubs,
}) })
} }
@ -28,7 +31,7 @@ describe('admin.vue', () => {
}) })
it('renders', () => { it('renders', () => {
expect(wrapper.is('div')).toBe(true) expect(wrapper.element.tagName).toBe('DIV')
}) })
}) })
}) })

View File

@ -1,15 +1,18 @@
import { config, mount } from '@vue/test-utils' import { mount } from '@vue/test-utils'
import GroupProfileSlug from './_slug.vue' import GroupProfileSlug from './_slug.vue'
const localVue = global.localVue const localVue = global.localVue
localVue.filter('date', (d) => d) localVue.filter('date', (d) => d)
config.stubs['client-only'] = '<span><slot /></span>' const stubs = {
config.stubs['v-popover'] = '<span><slot /></span>' 'client-only': true,
config.stubs['nuxt-link'] = '<span><slot /></span>' 'v-popover': true,
config.stubs['infinite-loading'] = '<span><slot /></span>' 'nuxt-link': true,
config.stubs['follow-list'] = '<span><slot /></span>' 'router-link': true,
'infinite-loading': true,
'follow-list': true,
}
describe('GroupProfileSlug', () => { describe('GroupProfileSlug', () => {
let wrapper let wrapper
@ -201,6 +204,7 @@ describe('GroupProfileSlug', () => {
mocks, mocks,
localVue, localVue,
data, data,
stubs,
}) })
} }

View File

@ -1,14 +1,16 @@
import { config, shallowMount, mount } from '@vue/test-utils' import { shallowMount, mount } from '@vue/test-utils'
import PostIndex from './index.vue' import PostIndex from './index.vue'
import Vuex from 'vuex' import Vuex from 'vuex'
import HashtagsFilter from '~/components/HashtagsFilter/HashtagsFilter' import HashtagsFilter from '~/components/HashtagsFilter/HashtagsFilter'
const localVue = global.localVue const localVue = global.localVue
config.stubs['client-only'] = '<span><slot /></span>' const stubs = {
config.stubs['router-link'] = '<span><slot /></span>' 'client-only': true,
config.stubs['nuxt-link'] = '<span><slot /></span>' 'router-link': true,
config.stubs['infinite-loading'] = '<span><slot /></span>' 'nuxt-link': true,
'infinite-loading': true,
}
describe('PostIndex', () => { describe('PostIndex', () => {
let wrapper let wrapper
@ -95,7 +97,7 @@ describe('PostIndex', () => {
it('clears the search when the filter menu emits clearSearch', () => { it('clears the search when the filter menu emits clearSearch', () => {
mocks.$route.query.hashtag = '#samplehashtag' mocks.$route.query.hashtag = '#samplehashtag'
wrapper = Wrapper() wrapper = Wrapper()
wrapper.find(HashtagsFilter).vm.$emit('clearSearch') wrapper.findComponent(HashtagsFilter).vm.$emit('clearSearch')
expect(wrapper.vm.hashtag).toBeNull() expect(wrapper.vm.hashtag).toBeNull()
}) })
@ -123,6 +125,7 @@ describe('PostIndex', () => {
store, store,
mocks, mocks,
localVue, localVue,
stubs,
}) })
} }

View File

@ -1,4 +1,4 @@
import { config, mount } from '@vue/test-utils' import { mount } from '@vue/test-utils'
import Vuex from 'vuex' import Vuex from 'vuex'
import Vue from 'vue' import Vue from 'vue'
import PostSlug from './index.vue' import PostSlug from './index.vue'
@ -6,10 +6,6 @@ import CommentList from '~/components/CommentList/CommentList'
import HcHashtag from '~/components/Hashtag/Hashtag' import HcHashtag from '~/components/Hashtag/Hashtag'
import VueMeta from 'vue-meta' import VueMeta from 'vue-meta'
config.stubs['client-only'] = '<span><slot /></span>'
config.stubs['nuxt-link'] = '<span><slot /></span>'
config.stubs['router-link'] = '<span><slot /></span>'
const localVue = global.localVue const localVue = global.localVue
localVue.directive('scrollTo', jest.fn()) localVue.directive('scrollTo', jest.fn())
localVue.use(VueMeta, { keyName: 'head' }) localVue.use(VueMeta, { keyName: 'head' })
@ -81,6 +77,9 @@ describe('PostSlug', () => {
}, },
} }
stubs = { stubs = {
'client-only': true,
'nuxt-link': true,
'router-link': true,
HcEditor: { render: () => {}, methods: { insertReply: jest.fn(() => null) } }, HcEditor: { render: () => {}, methods: { insertReply: jest.fn(() => null) } },
ContentViewer: true, ContentViewer: true,
} }
@ -148,7 +147,7 @@ describe('PostSlug', () => {
describe('reply method called when emitted reply received', () => { describe('reply method called when emitted reply received', () => {
it('CommentList', async () => { it('CommentList', async () => {
wrapper = await Wrapper() wrapper = await Wrapper()
wrapper.find(CommentList).vm.$emit('reply', { wrapper.findComponent(CommentList).vm.$emit('reply', {
id: 'commentAuthorId', id: 'commentAuthorId',
slug: 'ogerly', slug: 'ogerly',
}) })
@ -176,12 +175,12 @@ describe('PostSlug', () => {
it('are present', async () => { it('are present', async () => {
// Get length from backendData and compare against number of tags present in component. // Get length from backendData and compare against number of tags present in component.
expect(wrapper.findAll(HcHashtag).length).toBe(backendData.post.tags.length) expect(wrapper.findAllComponents(HcHashtag).length).toBe(backendData.post.tags.length)
}) })
it('are alphabetically ordered', async () => { it('are alphabetically ordered', async () => {
// Get all HcHastag components // Get all HcHastag components
const wrappers = wrapper.findAll(HcHashtag).wrappers const wrappers = wrapper.findAllComponents(HcHashtag).wrappers
// Exctract ID properties (tag names) from component. // Exctract ID properties (tag names) from component.
const ids = [] const ids = []
wrappers.forEach((x) => { wrappers.forEach((x) => {