Skip to content

Commit

Permalink
Setup basic unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
LeBenLeBen committed Dec 8, 2018
1 parent 0aa1541 commit 28b7659
Show file tree
Hide file tree
Showing 7 changed files with 5,903 additions and 3,600 deletions.
6 changes: 3 additions & 3 deletions .postcssrc.js
@@ -1,5 +1,5 @@
module.exports = {
plugins: {
autoprefixer: {}
}
}
autoprefixer: {},
},
};
17 changes: 17 additions & 0 deletions jest.config.js
@@ -0,0 +1,17 @@
module.exports = {
moduleFileExtensions: ['js', 'jsx', 'json', 'vue'],
transform: {
'^.+\\.vue$': 'vue-jest',
'.+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$':
'jest-transform-stub',
'^.+\\.jsx?$': 'babel-jest',
},
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
},
snapshotSerializers: ['jest-serializer-vue'],
testMatch: [
'**/tests/unit/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)',
],
testURL: 'http://localhost/',
};
9,363 changes: 5,774 additions & 3,589 deletions package-lock.json

Large diffs are not rendered by default.

23 changes: 15 additions & 8 deletions package.json
Expand Up @@ -3,16 +3,18 @@
"version": "0.1.0",
"private": true,
"scripts": {
"start": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint",
"deploy": "firebase deploy"
"deploy": "firebase deploy",
"start": "vue-cli-service serve",
"test:unit": "vue-cli-service test:unit",
"test": "npm run test:unit"
},
"dependencies": {
"date-fns": "^1.29.0",
"firebase": "^5.3.1",
"firebase": "^5.5.4",
"kanbasu": "^2.2.1",
"lodash": "^4.17.10",
"lodash": "^4.17.11",
"vue": "^2.5.17",
"vue-notification": "^1.3.13",
"vue-router": "^3.0.1",
Expand All @@ -21,12 +23,17 @@
"vuex": "^3.0.1"
},
"devDependencies": {
"@vue/cli-plugin-babel": "^3.0.0-rc.12",
"@vue/cli-plugin-eslint": "^3.0.0-rc.12",
"@vue/cli-service": "^3.0.0-rc.12",
"@vue/eslint-config-prettier": "^3.0.1",
"@vue/cli-plugin-babel": "^3.0.5",
"@vue/cli-plugin-eslint": "^3.0.5",
"@vue/cli-plugin-unit-jest": "^3.0.5",
"@vue/cli-service": "^3.0.5",
"@vue/eslint-config-prettier": "^3.0.5",
"@vue/test-utils": "^1.0.0-beta.20",
"babel-core": "7.0.0-bridge.0",
"babel-jest": "^23.0.1",
"babel-plugin-lodash": "^3.3.4",
"node-sass": "^4.9.0",
"prettier": "^1.14.3",
"sass-loader": "^7.0.1",
"vue-svg-icon-loader": "^2.1.1",
"vue-template-compiler": "^2.5.17"
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/.eslintrc.js
@@ -0,0 +1,5 @@
module.exports = {
env: {
jest: true,
},
};
56 changes: 56 additions & 0 deletions tests/unit/components/Quote.spec.js
@@ -0,0 +1,56 @@
import { shallowMount, createLocalVue } from '@vue/test-utils';
import Vuex from 'vuex';
import _ from 'lodash';

import Quote from '@/components/Quote.vue';
const localVue = createLocalVue();
localVue.use(Vuex);

describe('Quote.vue', () => {
let store;
let quote = {
id: 1,
text: ['Watson: excellent!', 'Sherlock: elementary.'],
author: 'Sherlock',
interlocutor: 'Watson',
date: '2018-01-01',
likes: 0,
likedBy: [],
};

beforeEach(() => {
store = new Vuex.Store({
state: {
user: {
uid: '1',
},
},
});
});

it('renders quote', () => {
const wrapper = shallowMount(Quote, {
propsData: {
quote: _.cloneDeep(quote),
},
store,
localVue,
stubs: ['router-link'],
});

expect(wrapper).toMatchSnapshot();
});

it('highlight like button if user has liked', () => {
const wrapper = shallowMount(Quote, {
propsData: {
quote: _.defaults({ likes: 1, likedBy: ['1'] }, quote),
},
store,
localVue,
stubs: ['router-link'],
});

expect(wrapper).toMatchSnapshot();
});
});
33 changes: 33 additions & 0 deletions tests/unit/components/__snapshots__/Quote.spec.js.snap
@@ -0,0 +1,33 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Quote.vue highlight like button if user has liked 1`] = `
<div class="quote">
<div class="quote__body">
<ul class="list-stacked list-stacked--divided">
<li>Watson: excellent!</li>
<li>Sherlock: elementary.</li>
</ul>
</div>
<div class="quote__meta"><strong>Sherlock</strong> <span> à <strong>Watson</strong></span>
le&nbsp;<router-link-stub to="/quote/1" class="text-nowrap">1 janvier 2018</router-link-stub> <button type="button" title="Je n’aime plus" class="btn btn--bare like like--liked">
<heart-alt-icon-stub class="like__icon icon"></heart-alt-icon-stub>
1
</button></div>
</div>
`;

exports[`Quote.vue renders quote 1`] = `
<div class="quote">
<div class="quote__body">
<ul class="list-stacked list-stacked--divided">
<li>Watson: excellent!</li>
<li>Sherlock: elementary.</li>
</ul>
</div>
<div class="quote__meta"><strong>Sherlock</strong> <span> à <strong>Watson</strong></span>
le&nbsp;<router-link-stub to="/quote/1" class="text-nowrap">1 janvier 2018</router-link-stub> <button type="button" title="J’aime" class="btn btn--bare like">
<heart-icon-stub class="like__icon icon"></heart-icon-stub>
0
</button></div>
</div>
`;

0 comments on commit 28b7659

Please sign in to comment.