Skip to content

Commit 9c07306

Browse files
committed
tests: add jest, and some example tests
1 parent d4e0773 commit 9c07306

File tree

9 files changed

+488
-428
lines changed

9 files changed

+488
-428
lines changed

.eslintrc.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,16 @@ module.exports = {
99
},
1010
},
1111
extends: [
12-
'plugin:@typescript-eslint/recommended', // Uses the recommended rules from the @typescript-eslint/eslint-plugin
13-
'plugin:prettier/recommended', // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
12+
// TODO: clean-up
13+
'plugin:vue/vue3-essential',
1414
'eslint:recommended',
15-
'plugin:vue/vue3-recommended',
15+
'@vue/typescript/recommended',
16+
'@vue/prettier',
17+
'@vue/prettier/@typescript-eslint',
18+
// 'plugin:@typescript-eslint/recommended', // Uses the recommended rules from the @typescript-eslint/eslint-plugin
19+
// 'plugin:prettier/recommended', // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
20+
// 'eslint:recommended',
21+
// 'plugin:vue/vue3-recommended',
1622
],
1723
// plugins: ['@typescript-eslint'],
1824
rules: {

package.json

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
"docs:dev": "vuepress dev docs --clean-cache",
1919
"docs:build": "vuepress build docs",
2020
"lint": "eslint 'src/components/**/*.{js,ts,tsx}'",
21-
"test": "jest --coverage",
22-
"test:clear": "jest --clearCache"
21+
"test": "jest -u",
22+
"test:clear": "jest --clearCache",
23+
"test:coverage": "jest --coverage"
2324
},
2425
"homepage": "https://coreui.io/vue/",
2526
"author": "The CoreUI Team (https://github.com/orgs/coreui/people)",
@@ -48,8 +49,10 @@
4849
"@typescript-eslint/eslint-plugin": "^4.29.3",
4950
"@typescript-eslint/parser": "^4.29.3",
5051
"@vue/compiler-sfc": "^3.2.5",
52+
"@vue/eslint-config-prettier": "^6.0.0",
53+
"@vue/eslint-config-typescript": "^7.0.0",
5154
"@vue/server-renderer": "^3.2.5",
52-
"@vue/test-utils": "^2.0.0-rc.4",
55+
"@vue/test-utils": "^2.0.0-0",
5356
"@vuepress/plugin-toc": "^2.0.0-beta.24",
5457
"auto-changelog": "^2.3.0",
5558
"babel-loader": "^8.2.2",
@@ -70,7 +73,7 @@
7073
"typescript": "4.3.5",
7174
"vue": "^3.2.6",
7275
"vue-docgen-cli": "^4.41.1",
73-
"vue-jest": "^5.0.0-alpha.7",
76+
"vue-jest": "^5.0.0-0",
7477
"vue-prism-component": "^2.0.0",
7578
"vue-router": "^4.0.11",
7679
"vue-types": "^4.0.3",
@@ -91,9 +94,9 @@
9194
"vue"
9295
],
9396
"transform": {
97+
".*\\.(ts)$": "ts-jest",
9498
".*\\.(vue)$": "vue-jest"
95-
},
96-
"testRegex": "/src/.*\\.(spec.tsx)$"
99+
}
97100
},
98101
"standard": {
99102
"ignore": [

src/__tests__/index.spec.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { shallowMount } from '@vue/test-utils'
2+
import { CAlert as Component } from './../../'
3+
4+
const ComponentName = 'CAlert'
5+
const wrapper = shallowMount(Component)
6+
const customWrapper = shallowMount(Component, {
7+
props: {
8+
color: 'success',
9+
},
10+
attrs: {
11+
class: 'bazinga',
12+
},
13+
slots: {
14+
default: 'Hello World!',
15+
},
16+
})
17+
18+
describe(`Loads and display ${ComponentName} component`, () => {
19+
it('has a name', () => {
20+
expect(Component.name).toMatch(ComponentName)
21+
})
22+
it('renders correctly', () => {
23+
expect(wrapper.element).toMatchSnapshot()
24+
})
25+
it('renders correctly with slot', () => {
26+
expect(customWrapper.element).toMatchSnapshot()
27+
})
28+
})
29+
30+
describe(`Customize ${ComponentName} component`, () => {
31+
it('has a prope class names', () => {
32+
expect(customWrapper.find('div').classes('alert')).toBe(true)
33+
expect(customWrapper.find('div').classes('alert-success')).toBe(true)
34+
})
35+
it('default slot contains text', () => {
36+
expect(customWrapper.text()).toBe('Hello World!')
37+
})
38+
})

src/components/alert/__tests__/CAlert.spec.tsx

Lines changed: 0 additions & 84 deletions
This file was deleted.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Loads and display CAlert component renders correctly 1`] = `
4+
<transition-stub>
5+
<div
6+
class="alert alert-undefined"
7+
>
8+
<!---->
9+
<!---->
10+
</div>
11+
</transition-stub>
12+
`;
13+
14+
exports[`Loads and display CAlert component renders correctly with slot 1`] = `
15+
<transition-stub
16+
class="bazinga"
17+
>
18+
<div
19+
class="alert alert-success alert-success"
20+
>
21+
22+
Hello World!
23+
24+
<!---->
25+
</div>
26+
</transition-stub>
27+
`;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { shallowMount } from '@vue/test-utils'
2+
import { CBadge as Component } from './../../'
3+
4+
const ComponentName = 'CBadge'
5+
const wrapper = shallowMount(Component)
6+
const customWrapper = shallowMount(Component, {
7+
props: {
8+
color: 'success',
9+
},
10+
attrs: {
11+
class: 'bazinga',
12+
},
13+
slots: {
14+
default: 'Hello World!',
15+
},
16+
})
17+
18+
describe(`Loads and display ${ComponentName} component`, () => {
19+
it('has a name', () => {
20+
expect(Component.name).toMatch(ComponentName)
21+
})
22+
it('renders correctly', () => {
23+
expect(wrapper.element).toMatchSnapshot()
24+
})
25+
it('renders correctly with slot', () => {
26+
expect(customWrapper.element).toMatchSnapshot()
27+
})
28+
})
29+
30+
describe(`Customize ${ComponentName} component`, () => {
31+
it('has a prope class names', () => {
32+
expect(customWrapper.classes('bazinga')).toBe(true)
33+
expect(customWrapper.classes('badge')).toBe(true)
34+
expect(customWrapper.classes('bg-success')).toBe(true)
35+
})
36+
it('default slot contains text', () => {
37+
expect(customWrapper.text()).toBe('Hello World!')
38+
})
39+
})
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Loads and display CBadge component renders correctly 1`] = `
4+
<span
5+
class="badge"
6+
/>
7+
`;
8+
9+
exports[`Loads and display CBadge component renders correctly with slot 1`] = `
10+
<span
11+
class="badge bg-success bazinga"
12+
>
13+
Hello World!
14+
</span>
15+
`;

0 commit comments

Comments
 (0)