Boilerplate code built on vue-cli 3.0, vuetify, jest, eslint, git hook script for pre-commit, post-merge.
git clone git@gitlab.com:sourcefit/vue-cli-veutify-boierplate.git
cd vue-cli-veutify-boierplate
npm install
npm run serve
Vue component testing is placed under tests/unit directory and has .spec.js extension.
Other JS testing is placed under tests/tests directory and has .test.js extension.
tests
──> __tests__
───> example.test.js // for normal js testing
──> unit
────> HelloWorld.spec.js // Vue component should be camelcase
HelloWorld.spec.js
/**
* Always use shallowMount because to isolate the component
*/
import { shallowMount } from "@vue/test-utils";
import HelloWorld from "@/components/HelloWorld.vue";
describe("HelloWorld.vue", () => {
it("renders is vue instance", () => {
/**
* mount the component to be tested
* using shallowMount
*/
const wrapper = shallowMount(HelloWorld);
expect(wrapper.isVueInstance()).toBeTruthy();
});
});
example.test.js
function sum(a, b) {
return a + b;
}
test("adds 1 + 2 to equal 3", () => {
expect(sum(1, 2)).toBe(3);
});
npm run test:unit
References