Skip to content

Commit

Permalink
chore: improve test config
Browse files Browse the repository at this point in the history
  • Loading branch information
qmhc committed Sep 11, 2023
1 parent 7bbde77 commit c5595ef
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 7 deletions.
3 changes: 1 addition & 2 deletions common/config/src/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ export function useProps<T extends Record<string, any>>(
const getDefault = () =>
(!isFunc && isFunction(defaultValue) ? defaultValue() : defaultValue) as T[keyof T]

import.meta.env.MODE !== 'test' &&
validator &&
validator &&
watch(
() => sourceProps[key],
value => {
Expand Down
18 changes: 18 additions & 0 deletions components/icon/tests/icon.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ describe('Icon', () => {
expect(wrapper.find('.vxp-icon').attributes('aria-hidden')).toEqual('true')
})

it('empty', () => {
const wrapper = mount(() => <Icon></Icon>)

expect(wrapper.find('.vxp-icon').exists()).toBe(true)
expect(wrapper.element.innerHTML).toEqual('')
})

it('icon prop', () => {
const wrapper = mount(() => <Icon icon={Spinner}></Icon>)

Expand Down Expand Up @@ -86,5 +93,16 @@ describe('Icon', () => {

await wrapper.setProps({ scale: 2 })
expect(wrapper.attributes('style')).toContain('font-size: 2em;')

await wrapper.setProps({ scale: NaN })
expect(wrapper.attributes('style')).toBeUndefined()
})

it('custom effect', async () => {
const wrapper = mount(Icon, {
props: { effect: 'effect', icon: Spinner }
})

expect(wrapper.classes()).toContain('effect')
})
})
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
"@vitejs/plugin-vue": "^4.3.4",
"@vitejs/plugin-vue-jsx": "^3.0.2",
"@vitest/coverage-c8": "^0.33.0",
"@vitest/coverage-v8": "^0.34.4",
"@vue/test-utils": "^2.4.1",
"conventional-changelog-angular": "^7.0.0",
"conventional-changelog-cli": "^4.0.0",
Expand Down
55 changes: 53 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@ export default defineConfig({
include: ['components/*/tests/*.spec.{ts,tsx}'],
environment: 'happy-dom',
clearMocks: true,
setupFiles: [resolve(__dirname, 'scripts/test-setup.ts')],
setupFiles: [resolve(rootDir, 'scripts/test-setup.ts')],
coverage: {
exclude: dirs.filter(f => f !== 'components').map(f => `${f}/**`),
reporter: ['text'],
exclude: [
...dirs.filter(f => f !== 'components').map(f => `${f}/**`),
'**/*.style.ts',
'**/*.css.ts'
],
reporter: ['text', 'html'],
extension: ['ts', 'tsx', 'vue']
},
testTimeout: 10000
Expand Down

0 comments on commit c5595ef

Please sign in to comment.