some cleaning and started to understand unittest with jest
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
import { HTTP } from './http-axios'
|
import { HTTP } from './http-axios'
|
||||||
// import { store } from 'modules/data/store'
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
getPosts (cb) {
|
getPosts (cb) {
|
||||||
|
|||||||
@@ -22,12 +22,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
// import store from './store'
|
|
||||||
// import datarest from 'components/data/datarest'
|
|
||||||
|
|
||||||
import { mapState, mapActions } from 'vuex'
|
import { mapState, mapActions } from 'vuex'
|
||||||
// import { mapState } from 'vuex'
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
computed: mapState({
|
computed: mapState({
|
||||||
@@ -42,5 +37,4 @@ export default {
|
|||||||
this.$store.dispatch('posts/getAllPosts')
|
this.$store.dispatch('posts/getAllPosts')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,12 +1,9 @@
|
|||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
import Vuex from 'vuex'
|
|
||||||
import router from './router'
|
import router from './router'
|
||||||
import store from './store'
|
import store from './store'
|
||||||
import App from './App'
|
import App from './App'
|
||||||
import 'assets/css/app.styl'
|
import 'assets/css/app.styl'
|
||||||
|
|
||||||
Vue.use(Vuex)
|
|
||||||
|
|
||||||
new Vue({
|
new Vue({
|
||||||
router,
|
router,
|
||||||
store,
|
store,
|
||||||
|
|||||||
+1
-6
@@ -2,16 +2,11 @@ import Vue from 'vue'
|
|||||||
import Vuex from 'vuex'
|
import Vuex from 'vuex'
|
||||||
import posts from './modules/posts'
|
import posts from './modules/posts'
|
||||||
|
|
||||||
Vue.use(Vuex)
|
|
||||||
|
|
||||||
// https://github.com/vuejs/vuex/tree/dev/examples/shopping-cart
|
// https://github.com/vuejs/vuex/tree/dev/examples/shopping-cart
|
||||||
|
|
||||||
// const debug = process.env.NODE_ENV !== 'production'
|
Vue.use(Vuex)
|
||||||
|
|
||||||
export default new Vuex.Store({
|
export default new Vuex.Store({
|
||||||
modules: {
|
modules: {
|
||||||
posts
|
posts
|
||||||
}
|
}
|
||||||
// strict: debug,
|
|
||||||
// plugins: debug ? [createLogger()] : []
|
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -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