-
-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(utils): [vue] add icon,install,vnode and global-node test (#16216)
* test(utils): [vue] add icon,install,vnode and global-node test * test(utils): [global-node] remove repeat code of useless
- Loading branch information
1 parent
e75cee1
commit 98ce640
Showing
4 changed files
with
170 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { shallowMount } from '@vue/test-utils' | ||
import { describe, expect, it } from 'vitest' | ||
import { TypeComponentsMap, ValidateComponentsMap } from '../..' | ||
|
||
describe('TypeComponentsMap', () => { | ||
it('Given a type "success", it should return SuccessFilled component', () => { | ||
const component = shallowMount(TypeComponentsMap.success) | ||
expect(component.exists()).toBe(true) | ||
}) | ||
|
||
it('Given a type "warning", it should return WarningFilled component', () => { | ||
const component = shallowMount(TypeComponentsMap.warning) | ||
expect(component.exists()).toBe(true) | ||
}) | ||
|
||
it('Given a type "error", it should return CircleCloseFilled component', () => { | ||
const component = shallowMount(TypeComponentsMap.error) | ||
expect(component.exists()).toBe(true) | ||
}) | ||
|
||
it('Given a type "info", it should return InfoFilled component', () => { | ||
const component = shallowMount(TypeComponentsMap.info) | ||
expect(component.exists()).toBe(true) | ||
}) | ||
}) | ||
|
||
describe('ValidateComponentsMap', () => { | ||
it('Given a validation state "validating", it should return Loading component', () => { | ||
const component = shallowMount(ValidateComponentsMap.validating) | ||
expect(component.exists()).toBe(true) | ||
}) | ||
|
||
it('Given a validation state "success", it should return CircleCheck component', () => { | ||
const component = shallowMount(ValidateComponentsMap.success) | ||
expect(component.exists()).toBe(true) | ||
}) | ||
|
||
it('Given a validation state "error", it should return CircleClose component', () => { | ||
const component = shallowMount(ValidateComponentsMap.error) | ||
expect(component.exists()).toBe(true) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import { createApp } from 'vue' | ||
import { describe, expect, it } from 'vitest' | ||
import { withInstall, withInstallDirective } from '../..' | ||
|
||
describe('withInstall', () => { | ||
it('it should add an install method to the main component', () => { | ||
const mainComponent = { | ||
name: 'MainComponent', | ||
render: () => null, | ||
} | ||
|
||
const componentWithInstall = withInstall(mainComponent) | ||
expect(typeof componentWithInstall.install).toBe('function') | ||
}) | ||
|
||
it('it should register the main component and extra components when calling install', () => { | ||
const mainComponent = { | ||
name: 'MainComponent', | ||
render: () => null, | ||
} | ||
|
||
const extraComponents = { | ||
ExtraComponent: { | ||
name: 'ExtraComponent', | ||
render: () => null, | ||
}, | ||
} | ||
|
||
const app = createApp({}) | ||
const componentWithInstall = withInstall(mainComponent, extraComponents) | ||
|
||
componentWithInstall.install?.(app) | ||
|
||
expect(app.component('MainComponent')).toBeTruthy() | ||
expect(app.component('ExtraComponent')).toBeTruthy() | ||
}) | ||
|
||
it('it should add extra components to the main component when provided', () => { | ||
const mainComponent = { | ||
name: 'MainComponent', | ||
render: () => null, | ||
} | ||
|
||
const extraComponents = { | ||
ExtraComponent: { | ||
name: 'ExtraComponent', | ||
render: () => null, | ||
}, | ||
} | ||
|
||
const componentWithInstall = withInstall(mainComponent, extraComponents) | ||
|
||
expect(componentWithInstall.ExtraComponent).toBeTruthy() | ||
}) | ||
|
||
it('it should not add extra components if none provided', () => { | ||
const mainComponent = { | ||
name: 'MainComponent', | ||
render: () => null, | ||
} | ||
|
||
const componentWithInstall = withInstall(mainComponent) | ||
|
||
expect(componentWithInstall.ExtraComponent).toBeFalsy() | ||
}) | ||
}) | ||
|
||
describe('withInstallDirective', () => { | ||
it('it should add an install method to the directive', () => { | ||
const directive = { | ||
mounted: () => null, | ||
unmounted: () => null, | ||
} | ||
|
||
const directiveWithInstall = withInstallDirective( | ||
directive, | ||
'test-directive' | ||
) | ||
expect(typeof directiveWithInstall.install).toBe('function') | ||
}) | ||
|
||
it('it should register the directive when calling install', () => { | ||
const directive = { | ||
mounted: () => null, | ||
unmounted: () => null, | ||
} | ||
|
||
const app = createApp({}) | ||
const directiveWithInstall = withInstallDirective( | ||
directive, | ||
'test-directive' | ||
) | ||
|
||
directiveWithInstall.install?.(app) | ||
|
||
expect(app.directive('test-directive')).toBeTruthy() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { describe, expect, it } from 'vitest' | ||
import { ensureOnlyChild } from '../..' | ||
|
||
describe('ensureOnlyChild', () => { | ||
it('it should throw an error if input is not an array or undefined', () => { | ||
expect(() => { | ||
ensureOnlyChild('not an array' as any) | ||
}).toThrow('expect to receive a single Vue element child') | ||
}) | ||
|
||
it('it should throw an error if input array has more than one element', () => { | ||
expect(() => { | ||
ensureOnlyChild([1, 2]) | ||
}).toThrow('expect to receive a single Vue element child') | ||
}) | ||
|
||
it('it should return the only child if input is an array with one element', () => { | ||
const child = { type: 'div' } | ||
expect(ensureOnlyChild([child as any])).toEqual(child) | ||
}) | ||
}) |