some cleaning and started to understand unittest with jest
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import { shallowMount } from '@vue/test-utils'
|
||||
import Posts from '@/components/Home/Posts'
|
||||
|
||||
// https://alligator.io/vuejs/testing-vue-with-jest/
|
||||
|
||||
function mountComponentWithProps (Component, propsData) {
|
||||
const Constructor = Vue.extend(Component);
|
||||
const vm = new Constructor({
|
||||
propsData
|
||||
}).$mount();
|
||||
|
||||
return vm.$el;
|
||||
}
|
||||
|
||||
describe('Posts.vue', () => {
|
||||
it('posts should not be empty', () => {
|
||||
const PostsData = mountComponentWithProps(Posts, { all: [] });
|
||||
const allData = PostData.all;
|
||||
|
||||
console.log(allData)
|
||||
|
||||
expect(allData).toBe([])
|
||||
})
|
||||
})
|
||||
@@ -1,14 +0,0 @@
|
||||
import { shallowMount } from '@vue/test-utils'
|
||||
import WelcomeMessage from '@/components/Home/WelcomeMessage'
|
||||
|
||||
describe('WelcomeMessage.vue', () => {
|
||||
it('renders props.msg when passed', () => {
|
||||
const name = 'tester'
|
||||
|
||||
const wrapper = shallowMount(WelcomeMessage, {
|
||||
propsData: { name }
|
||||
})
|
||||
|
||||
expect(wrapper.text()).toBe('Hello tester from my Vue.js page, built with Webpack 4!')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user