Skip to content

Commit

Permalink
🌟feat(all): add vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
Ten-K committed Nov 30, 2022
1 parent 982beb4 commit 758e44f
Show file tree
Hide file tree
Showing 8 changed files with 575 additions and 8 deletions.
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
. "$(dirname -- "$0")/_/husky.sh"

npm run pre-commit
npm run test
22 changes: 22 additions & 0 deletions __tests__/filpper.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { mount } from '@vue/test-utils'
import { describe, expect, it } from 'vitest'
import Filpper from '../src/components/filpper'

describe('Filpper', () => {
it('默认props渲染', () => {
const wrapper = mount(Filpper)
expect(wrapper.html()).toContain('<div class="digital front number0"></div>')
expect(wrapper.html()).toContain('<div class="digital back number1"></div>')
})

it('接收frontText, backText参数渲染', async () => {
const wrapper = mount(Filpper, {
propsData: {
frontText: 1,
backText: 2
}
})
expect(wrapper.html()).toContain('<div class="digital front number1"></div>')
expect(wrapper.html()).toContain('<div class="digital back number2"></div>')
})
})
18 changes: 18 additions & 0 deletions __tests__/utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { describe, test, expect } from 'vitest'
import { formatDate, padLeftZero } from '../src/utils'

describe('时间格式化', () => {
test('将时间转化为hhiiss格式', () => {
expect(formatDate(new Date(1669791839049), 'hhiiss')).toBe('150359')
})
})

describe('日期时间补零', () => {
test('当时间小于十补零', () => {
expect(padLeftZero('1')).toBe('01')
})

test('当时间大于等于十返回原始值', () => {
expect(padLeftZero('10')).toBe('10')
})
})
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
"pre-commit": "lint-staged",
"postinstallmac": "git config core.hooksPath .husky && chmod 700 .husky/*",
"eslint": "eslint --cache --max-warnings 0 \"{src,mock}/**/*.{vue,ts,js,tsx}\" --fix",
"commit": "git add . && git-cz"
"commit": "git add . && git-cz",
"test": "vitest"
},
"dependencies": {
"vue": "^3.2.45"
Expand All @@ -54,9 +55,11 @@
"@commitlint/config-angular": "^17.3.0",
"@commitlint/cz-commitlint": "^17.3.0",
"@rollup/plugin-terser": "^0.1.0",
"@types/node": "^18.11.9",
"@typescript-eslint/parser": "^5.45.0",
"@vitejs/plugin-vue": "^3.2.0",
"@vitejs/plugin-vue-jsx": "^2.1.1",
"@vue/test-utils": "^2.2.4",
"autoprefixer": "^10.4.13",
"commitizen": "^4.2.5",
"cssnano": "^5.1.14",
Expand All @@ -69,13 +72,16 @@
"eslint-plugin-vue": "^9.8.0",
"husky": "^8.0.2",
"inquirer": "^8.2.5",
"jsdom": "^20.0.3",
"lint-staged": "^12.5.0",
"postcss": "^8.4.19",
"prettier": "^2.8.0",
"resize-observer-polyfill": "^1.5.1",
"typescript": "^4.9.3",
"vite": "^3.2.4",
"vite-plugin-dts": "^1.7.1",
"vite-plugin-libfile": "^1.0.2",
"vitest": "^0.25.3",
"vue-tsc": "^0.39.5",
"web-norm": "^1.0.27"
},
Expand Down
Loading

0 comments on commit 758e44f

Please sign in to comment.