Skip to content

Commit 01f03ab

Browse files
committed
add unit and e2e testing
1 parent 4378bfc commit 01f03ab

File tree

14 files changed

+8207
-493
lines changed

14 files changed

+8207
-493
lines changed

e2e/javascript/index.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import 'expect-puppeteer';
2+
3+
describe('Google', () => {
4+
beforeAll(async () => {
5+
await page.goto('http://localhost:3000')
6+
});
7+
8+
it('should display playground text on page', async () => {
9+
await expect(page).toMatch('Vue 3.0.5 Playground');
10+
});
11+
});

e2e/typescript/index.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import 'expect-puppeteer';
2+
3+
describe('Google', () => {
4+
beforeAll(async () => {
5+
await page.goto('http://localhost:3000')
6+
});
7+
8+
it('should display playground text on page', async () => {
9+
await expect(page).toMatch('Vue 3.0.5 Playground');
10+
});
11+
});

jest.e2e.config.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
moduleFileExtensions: [
3+
'js',
4+
'ts',
5+
'json'
6+
],
7+
preset: 'jest-puppeteer',
8+
transform: {
9+
'^.+\\.js$': 'babel-jest',
10+
'^.+\\.ts$': 'ts-jest'
11+
}
12+
};

jest.unit.config.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module.exports = {
2+
moduleFileExtensions: [
3+
'js',
4+
'ts',
5+
'json',
6+
'vue'
7+
],
8+
transform: {
9+
'^.+\\.js$': 'babel-jest',
10+
'^.+\\.ts$': 'ts-jest',
11+
'^.+\\.vue$': 'vue-jest'
12+
}
13+
};

package-lock.json

Lines changed: 8071 additions & 488 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,50 @@
88
"scripts": {
99
"start": "vite",
1010
"build": "vite build",
11-
"test": "echo 'No test specified'"
11+
"test": "npm run test:unit:javascript && npm run test:unit:typescript",
12+
"test:unit:javascript": "jest --config=jest.unit.config.js src-javascript",
13+
"test:unit:typescript": "jest --config=jest.unit.config.js src-typescript",
14+
"test:e2e:javascript": "start-server-and-test start http://localhost:3000 e2e:javascript",
15+
"test:e2e:typescript": "start-server-and-test start http://localhost:3000 e2e:typescript",
16+
"e2e:javascript": "jest --config=jest.e2e.config.js e2e/javascript",
17+
"e2e:typescript": "jest --config=jest.e2e.config.js e2e/typescript"
1218
},
1319
"dependencies": {
1420
"vue": "^3.0.5",
1521
"vue-router": "^4.0.1",
1622
"vuex": "^4.0.0-rc.2"
1723
},
1824
"devDependencies": {
25+
"@babel/preset-env": "^7.12.11",
26+
"@types/expect-puppeteer": "^4.4.5",
27+
"@types/jest-environment-puppeteer": "^4.4.1",
28+
"@types/puppeteer": "^5.4.2",
1929
"@vitejs/plugin-vue": "^1.1.2",
2030
"@vitejs/plugin-vue-jsx": "^1.0.2",
2131
"@vue/compiler-sfc": "^3.0.5",
22-
"vite": "^2.0.0-beta.56"
32+
"@vue/test-utils": "2.0.0-alpha.3",
33+
"babel-core": "^7.0.0-bridge.0",
34+
"babel-jest": "^26.6.3",
35+
"expect-puppeteer": "^4.4.0",
36+
"jest": "^26.6.3",
37+
"jest-puppeteer": "^4.4.0",
38+
"puppeteer": "^5.5.0",
39+
"start-server-and-test": "^1.11.7",
40+
"ts-jest": "^26.5.0",
41+
"typescript": "^4.1.3",
42+
"vite": "^2.0.0-beta.56",
43+
"vue-jest": "^5.0.0-alpha.8"
44+
},
45+
"babel": {
46+
"presets": [
47+
[
48+
"@babel/preset-env",
49+
{
50+
"targets": {
51+
"node": "current"
52+
}
53+
}
54+
]
55+
]
2356
}
2457
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { mount } from '@vue/test-utils';
2+
import Coupon from './Coupon.vue';
3+
4+
describe('Coupon', () => {
5+
it('should trigger coupon percent on button click', () => {
6+
const wrapper = mount(Coupon, { props: { percent: 10 } });
7+
8+
wrapper.find('.btn').trigger('click');
9+
10+
expect(wrapper.emitted().redeem).toHaveLength(1);
11+
expect(wrapper.emitted().redeem[0]).toEqual([10]);
12+
});
13+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { mount } from '@vue/test-utils';
2+
import Username from './Username.vue';
3+
4+
describe('Username', () => {
5+
it('should display required text', () => {
6+
const wrapper = mount(Username);
7+
8+
expect(wrapper.find('.invalid-feedback').text()).toEqual('Your username is required.');
9+
});
10+
});

src-javascript/components/Username.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<label for="username">Default label</label>
55
</slot>
66
<div class="input-group">
7-
<div class="input-group-prepend" v-at-sign:foo.a.b="label"></div>
7+
<div class="input-group-prepend"></div>
88
<input type="text" class="form-control" id="username" placeholder="Username" />
99
<div class="invalid-feedback" style="width: 100%;">
1010
Your username is required.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { mount } from '@vue/test-utils';
2+
import Coupon from './Coupon.vue';
3+
4+
describe('Coupon', () => {
5+
it('should trigger coupon percent on button click', () => {
6+
const wrapper = mount(Coupon, { props: { percent: 10 } });
7+
8+
wrapper.find<HTMLButtonElement>('.btn').trigger('click');
9+
10+
expect(wrapper.emitted().redeem).toHaveLength(1);
11+
expect(wrapper.emitted().redeem[0]).toEqual([10]);
12+
});
13+
});

0 commit comments

Comments
 (0)