File tree Expand file tree Collapse file tree 13 files changed +91
-28
lines changed
Expand file tree Collapse file tree 13 files changed +91
-28
lines changed Original file line number Diff line number Diff line change @@ -477,12 +477,41 @@ https://docs.npmjs.com/getting-started/updating-local-packages
477477
478478## Testing
479479
480+ #### Install vue-test-utils
481+
482+ https://github.com/vuejs/vue-test-utils
483+
484+ ` npm install --save-dev @vue/test-utils `
485+
480486#### Jest
481487
482488https://facebook.github.io/jest/
483489
484490Intro-Blogpost: https://blog.codecentric.de/2017/06/javascript-unit-tests-sind-schwer-aufzusetzen-keep-calm-use-jest/
485491
492+ https://github.com/vuejs/vue-test-utils-jest-example
493+
494+ ###### Jest Configuration
495+
496+ * [ package.json] ( frontend/package.json ) :
497+
498+ ```
499+ "scripts": {
500+ ...
501+ "unit": "jest --config test/unit/jest.conf.js --coverage",
502+ ....
503+ },
504+ ```
505+
506+ * [ frontend/test/unit/jest.conf.js] ( frontend/test/unit/jest.conf.js )
507+
508+ ###### Run Unit tests
509+
510+ ` npm run unit `
511+
512+ Run all tests (incl. E2E): ` npm test `
513+
514+
486515#### E2E tests with Nightwatch
487516
488517http://nightwatchjs.org/
Original file line number Diff line number Diff line change 2222 "vue-router" : " ^3.0.1"
2323 },
2424 "devDependencies" : {
25+ "@vue/test-utils" : " ^1.0.0-beta.20" ,
2526 "autoprefixer" : " ^7.1.2" ,
2627 "babel-core" : " ^6.26.3" ,
2728 "babel-helper-vue-jsx-merge-props" : " ^2.0.3" ,
Original file line number Diff line number Diff line change 11<template >
22 <div id =" app" >
3- <router-view ></router-view >
3+ <router-view :hellomsg = " msg " ></router-view >
44 </div >
55</template >
66
77<script >
8+
89export default {
9- name: ' app'
10+ name: ' app' ,
11+ data () {
12+ return {
13+ msg: ' Welcome to your Vue.js powered Spring Boot App'
14+ }
15+ }
1016}
1117 </script >
1218
Original file line number Diff line number Diff line change 11<template >
22 <div class =" hello" >
33 <img src =" ./../assets/spring-boot-vuejs-logo.png" >
4- <h1 >{{ msg }}</h1 >
4+ <h1 >{{ hellomsg }}</h1 >
55 <h2 >See the sources here: </h2 >
66 <ul >
77 <li ><a href =" https://github.com/jonashackt/spring-boot-vuejs" target =" _blank" >github.com/jonashackt/spring-boot-vuejs</a ></li >
2121<script >
2222export default {
2323 name: ' hello' ,
24-
25- data () {
26- return {
27- msg: ' Welcome to your Vue.js powered Spring Boot App'
28- }
29- }
24+ props: { hellomsg: { type: String , required: true } }
3025}
3126
3227 </script >
Original file line number Diff line number Diff line change 11<template >
2- <div class =" service " >
2+ <div class =" user " >
33 <h1 >Create User</h1 >
44
55 <h3 >Just some database interaction...</h3 >
2323 import {AXIOS } from ' ./http-common'
2424
2525 export default {
26- name: ' service ' ,
26+ name: ' user ' ,
2727
2828 data () {
2929 return {
Original file line number Diff line number Diff line change 11import Vue from 'vue'
2- import Router from 'vue-router'
2+ import VueRouter from 'vue-router'
33import Hello from '@/components/Hello'
44import Service from '@/components/Service'
55import Bootstrap from '@/components/Bootstrap'
66import User from '@/components/User'
77
8- Vue . use ( Router )
8+ Vue . use ( VueRouter )
99
1010export default new Router ( {
1111 routes : [
Original file line number Diff line number Diff line change 11{
22 "env": {
3- "mocha ": true
3+ "jest ": true
44 },
55 "globals": {
6- "expect": true,
7- "sinon": true
86 }
97}
Original file line number Diff line number Diff line change @@ -19,7 +19,6 @@ module.exports = {
1919 ] ,
2020 snapshotSerializers : [ '<rootDir>/node_modules/jest-serializer-vue' ] ,
2121 setupFiles : [ '<rootDir>/test/unit/setup' ] ,
22- mapCoverage : true ,
2322 coverageDirectory : '<rootDir>/test/unit/coverage' ,
2423 collectCoverageFrom : [
2524 'src/**/*.{js,vue}' ,
Original file line number Diff line number Diff line change 1+ import { shallowMount , createLocalVue } from '@vue/test-utils' ;
2+ import VueRouter from 'vue-router'
3+ import App from '@/App' ;
4+
5+ const localVue = createLocalVue ( )
6+ localVue . use ( VueRouter )
7+ const router = new VueRouter ( )
8+
9+ describe ( 'App component should' , ( ) => {
10+ it ( 'render without crashing' , ( ) => {
11+ const wrapper = shallowMount ( App , {
12+ localVue,
13+ router
14+ } ) ;
15+ expect ( wrapper . find ( 'hello' ) ) . toBeDefined ( ) ;
16+ } ) ;
17+ } ) ;
You can’t perform that action at this time.
0 commit comments