├── .gitignore ├── README.md ├── babel.config.js ├── jest.config.js ├── package.json ├── specs ├── alert.spec.js ├── exercise-1.spec.js ├── exercise-2.spec.js ├── fruits.spec.js ├── github.spec.js ├── salad.spec.js ├── stubs.spec.js ├── temp.spec.js └── test.spec.js └── src ├── alert-message.vue ├── components └── list-item.vue ├── exercise-1.vue ├── exercise-2.vue ├── fruit-basket.vue ├── github-card.vue ├── list.vue ├── salad-bowl.vue ├── store └── salad-store.js ├── temprature.vue └── test.vue /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .vscode/settings.json 3 | yarn.lock 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Testing Vue.js Components 2 | 3 | [![](https://vueschool.s3.amazonaws.com/9318e19655ce267304ebf5df7eca7154/testing-vuejs-components.png)](https://vueschool.io/courses/learn-how-to-test-vuejs-components) 4 | 5 | This repository contains the the starting point of the [Testing Vue.js Components](https://vueschool.io/courses/learn-how-to-test-vuejs-components) course. 6 | 7 | Learn how to test your Vue.js components like a pro with Jest and the official unit testing library for Vue.js - Vue Test Utils 8 | 9 | In this course, you’ll learn everything you need to know to write proper unit tests for your Vue components. 10 | 11 | Not sure how to mount and render your component to perform assertions. Not sure what you should and shouldn't test? Or how to test a specific thing? This course is for you! 12 | 13 | **By the end of this testing course you will know** 14 | - Which tools are required for an efficient testing workflow 15 | - How to mount and render your Vue components 16 | - How to programmatically interact with your components through Vue Test Utils 17 | - How to test computed properties and watchers 18 | - How to test Vue.js lifecycle methods 19 | - How to traverse the DOM and test … 20 | - How to stub child components 21 | - How to test that a Vuex Store is injected properly 22 | 23 | You need a basic understanding of testing in JavaScript and Jest. We recommend watching [JavaScript Testing Fundamentals](https://vueschool.io/courses/javascript-testing-fundamentals) and [Test with Jest](https://vueschool.io/courses/test-with-jest) if you're not already familiar with the topics. 24 | 25 | [Click here to watch the testing course](https://vueschool.io/courses/learn-how-to-test-vuejs-components). -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | [ 4 | '@babel/preset-env', 5 | { 6 | targets: { 7 | node: 'current', 8 | }, 9 | }, 10 | ], 11 | ], 12 | }; 13 | -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | verbose: true, 3 | roots: ["/src/", "/specs/"], 4 | moduleFileExtensions: ['js', 'vue'], 5 | moduleNameMapper: { 6 | '^@/(.*)$': '/src/$1', 7 | }, 8 | transform: { 9 | "^.+\\.js$": "babel-jest", 10 | }, 11 | snapshotSerializers: [ 12 | "/node_modules/jest-serializer-vue" 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vue-school-test-utils-base", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "repository": "https://github.com/codebryo/vue-school-test-utils-base.git", 6 | "author": "Roman Kuba ", 7 | "license": "MIT", 8 | "dependencies": { 9 | "@babel/core": "^7.3.4", 10 | "@babel/preset-env": "^7.3.4", 11 | "babel-core": "^7.0.0-bridge.0", 12 | "babel-jest": "^24.5.0", 13 | "jest": "^24.5.0", 14 | "jest-serializer-vue": "^2.0.2", 15 | "vue": "^2.6.9", 16 | "vuex": "^3.1.1" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /specs/alert.spec.js: -------------------------------------------------------------------------------- 1 | import AlertMessage from '@/alert-message' 2 | import { mount } from '@vue/test-utils' 3 | -------------------------------------------------------------------------------- /specs/exercise-1.spec.js: -------------------------------------------------------------------------------- 1 | import UserList from '@/exercise-1'; 2 | import { mount } from '@vue/test-utils'; 3 | -------------------------------------------------------------------------------- /specs/exercise-2.spec.js: -------------------------------------------------------------------------------- 1 | import ExerciseForm from '@/exercise-2'; 2 | import { mount } from '@vue/test-utils'; 3 | -------------------------------------------------------------------------------- /specs/fruits.spec.js: -------------------------------------------------------------------------------- 1 | import FruitBasket from '@/fruit-basket' 2 | import { mount } from '@vue/test-utils' 3 | -------------------------------------------------------------------------------- /specs/github.spec.js: -------------------------------------------------------------------------------- 1 | import GithubCard from '@/github-card' 2 | import { mount } from '@vue/test-utils' 3 | 4 | describe('methods', () => { 5 | 6 | }) 7 | -------------------------------------------------------------------------------- /specs/salad.spec.js: -------------------------------------------------------------------------------- 1 | import Vuex from 'vuex' 2 | import Vue from 'vue' 3 | import { mount } from '@vue/test-utils' 4 | 5 | import SaladBowlComponent from '@/salad-bowl' 6 | import saladStore from '@/store/salad-store' 7 | -------------------------------------------------------------------------------- /specs/stubs.spec.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vueschool/testing-vue-components/62594cb4d611dcbfd3de177d0b9726d68302e1ad/specs/stubs.spec.js -------------------------------------------------------------------------------- /specs/temp.spec.js: -------------------------------------------------------------------------------- 1 | import Temprature from '@/temprature' 2 | import { mount } from '@vue/test-utils' 3 | -------------------------------------------------------------------------------- /specs/test.spec.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vueschool/testing-vue-components/62594cb4d611dcbfd3de177d0b9726d68302e1ad/specs/test.spec.js -------------------------------------------------------------------------------- /src/alert-message.vue: -------------------------------------------------------------------------------- 1 | 7 | 8 | 41 | 42 | -------------------------------------------------------------------------------- /src/components/list-item.vue: -------------------------------------------------------------------------------- 1 | 4 | 5 | 12 | -------------------------------------------------------------------------------- /src/exercise-1.vue: -------------------------------------------------------------------------------- 1 | 9 | 10 | 34 | -------------------------------------------------------------------------------- /src/exercise-2.vue: -------------------------------------------------------------------------------- 1 | 16 | 17 | 37 | -------------------------------------------------------------------------------- /src/fruit-basket.vue: -------------------------------------------------------------------------------- 1 | 13 | 14 | 32 | -------------------------------------------------------------------------------- /src/github-card.vue: -------------------------------------------------------------------------------- 1 | 17 | 18 | 41 | -------------------------------------------------------------------------------- /src/list.vue: -------------------------------------------------------------------------------- 1 | 12 | 13 | 34 | 35 | 38 | -------------------------------------------------------------------------------- /src/salad-bowl.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 22 | -------------------------------------------------------------------------------- /src/store/salad-store.js: -------------------------------------------------------------------------------- 1 | export default { 2 | state() { 3 | return { 4 | salad: [] 5 | } 6 | }, 7 | 8 | mutations: { 9 | addIngredient(state, ingredient) { 10 | state.salad.push(ingredient) 11 | } 12 | }, 13 | 14 | actions: { 15 | addIngredient({ commit }, ingredient) { 16 | commit('addIngredient', ingredient) 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/temprature.vue: -------------------------------------------------------------------------------- 1 | 7 | 8 | 47 | 48 | -------------------------------------------------------------------------------- /src/test.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 17 | --------------------------------------------------------------------------------