Skip to content

Commit 752f28a

Browse files
committed
test package added.
1 parent d31a648 commit 752f28a

File tree

8 files changed

+1521
-44
lines changed

8 files changed

+1521
-44
lines changed

jest.config.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
module.exports = {
2+
moduleFileExtensions: [
3+
'js',
4+
'jsx',
5+
'json',
6+
'vue'
7+
],
8+
transform: {
9+
'^.+\\.vue$': 'vue-jest',
10+
'.+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$': 'jest-transform-stub',
11+
'^.+\\.jsx?$': 'babel-jest'
12+
},
13+
transformIgnorePatterns: [
14+
'/node_modules/'
15+
],
16+
moduleNameMapper: {
17+
'^@/(.*)$': '<rootDir>/src/$1'
18+
},
19+
snapshotSerializers: [
20+
'jest-serializer-vue'
21+
],
22+
testMatch: [
23+
'**/tests/unit/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)'
24+
],
25+
testURL: 'http://localhost/',
26+
watchPlugins: [
27+
'jest-watch-typeahead/filename',
28+
'jest-watch-typeahead/testname'
29+
]
30+
}

package.json

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22
"name": "vue-toastr",
33
"version": "2.1.0",
44
"description": "Toastr for Vue.js no jquery dependencies",
5+
"author": "s4l1h",
56
"scripts": {
67
"build": "vue-cli-service build",
8+
"test": "vue-cli-service test",
79
"lint": "vue-cli-service lint",
810
"demo": "vue-cli-service demo",
911
"docs": "npm run docs:serve",
1012
"docs:build": "vue-cli-service docs --mode build",
1113
"docs:serve": "vue-cli-service docs --mode serve",
12-
"prepublish": "vue-cli-service lint && vue-cli-service docs --mode build && vue-cli-service build"
14+
"prepublish": "vue-cli-service lint && vue-cli-service docs --mode build && vue-cli-service build",
15+
"test:unit": "vue-cli-service test:unit"
1316
},
1417
"main": "dist/vue-toastr.common.js",
1518
"module": "dist/vue-toastr.esm.js",
@@ -25,8 +28,12 @@
2528
"devDependencies": {
2629
"@vue/cli-plugin-babel": "^3.8.0",
2730
"@vue/cli-plugin-eslint": "^3.8.0",
31+
"@vue/cli-plugin-unit-jest": "^3.8.0",
2832
"@vue/cli-service": "^3.8.0",
33+
"@vue/test-utils": "1.0.0-beta.29",
34+
"babel-core": "7.0.0-bridge.0",
2935
"babel-eslint": "^10.0.1",
36+
"babel-jest": "^23.6.0",
3037
"eslint": "^5.16.0",
3138
"eslint-plugin-vue": "^5.0.0",
3239
"node-sass": "^4.12.0",
@@ -58,22 +65,21 @@
5865
"> 1%",
5966
"last 2 versions"
6067
],
61-
"jsdelivr": "dist/vue-toastr.umd.min.js",
62-
"sideeffects": false,
63-
"repository": {
64-
"type": "git",
65-
"url": "git+https://github.com/s4l1h/vue-toastr.git"
68+
"bugs": {
69+
"url": "https://github.com/s4l1h/vue-toastr/issues"
6670
},
71+
"homepage": "https://github.com/s4l1h/vue-toastr#readme",
72+
"jsdelivr": "dist/vue-toastr.umd.min.js",
6773
"keywords": [
6874
"vuejs",
6975
"vue",
7076
"vue-component",
7177
"component"
7278
],
73-
"author": "s4l1h",
7479
"license": "MIT",
75-
"bugs": {
76-
"url": "https://github.com/s4l1h/vue-toastr/issues"
80+
"repository": {
81+
"type": "git",
82+
"url": "git+https://github.com/s4l1h/vue-toastr.git"
7783
},
78-
"homepage": "https://github.com/s4l1h/vue-toastr#readme"
84+
"sideeffects": false
7985
}

tests/unit/.eslintrc.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
env: {
3+
jest: true
4+
}
5+
}

tests/unit/Toast.spec.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { shallowMount } from "@vue/test-utils";
2+
import Toast from "@/components/Toast.vue";
3+
4+
const mockProps = {
5+
data: {
6+
msg: "Toast Msg",
7+
progressbar: false,
8+
timeout: 1000,
9+
title: "Toast Title",
10+
type: "error"
11+
}
12+
};
13+
describe("Toast.vue", () => {
14+
// it("default props value", () => {
15+
// const wrapper = shallowMount(Toast, {});
16+
// expect(wrapper.props()).toEqual(mockProps);
17+
// });
18+
19+
it("renders props when passed", () => {
20+
const wrapper = shallowMount(Toast, {
21+
propsData: mockProps
22+
});
23+
expect(wrapper.props()).toEqual(mockProps);
24+
});
25+
26+
it("match attributes", () => {
27+
const wrapper = shallowMount(Toast, {
28+
propsData: mockProps
29+
});
30+
expect(wrapper.attributes()).toEqual({
31+
class: "toast toast-error",
32+
style: "display: block;"
33+
});
34+
});
35+
36+
it("matches snapshot", () => {
37+
const wrapper = shallowMount(Toast, {
38+
propsData: mockProps
39+
});
40+
expect(wrapper.html()).toMatchSnapshot();
41+
});
42+
});

tests/unit/ToastProgress.spec.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { shallowMount } from "@vue/test-utils";
2+
import ToastProgress from "@/components/ToastProgress.vue";
3+
4+
describe("ToastProgress.vue", () => {
5+
it("default props value", () => {
6+
const wrapper = shallowMount(ToastProgress, {});
7+
expect(wrapper.props()).toEqual({ percent: 100 });
8+
});
9+
10+
it("renders props.percent when passed", () => {
11+
const props = { percent: 90 };
12+
const wrapper = shallowMount(ToastProgress, {
13+
propsData: props
14+
});
15+
expect(wrapper.props()).toEqual(props);
16+
});
17+
18+
it("match attributes", () => {
19+
const wrapper = shallowMount(ToastProgress, {
20+
propsData: { percent: 90 }
21+
});
22+
expect(wrapper.attributes()).toEqual({
23+
class: "toast-progress",
24+
style: "width: 90%;"
25+
});
26+
});
27+
28+
it("matches snapshot", () => {
29+
const wrapper = shallowMount(ToastProgress, {
30+
propsData: { percent: 90 }
31+
});
32+
expect(wrapper.html()).toMatchSnapshot();
33+
});
34+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Toast.vue matches snapshot 1`] = `
4+
<div class="toast toast-error" style="display: block;">
5+
<!---->
6+
<div class="toast-title">Toast Title</div>
7+
<div class="toast-message">Toast Msg</div>
8+
</div>
9+
`;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`ToastProgress.vue matches snapshot 1`] = `<div class="toast-progress" style="width: 90%;"></div>`;

0 commit comments

Comments
 (0)