Files
element-plus/packages/utils/__tests__/vue/install.test.ts
一只前端汪 7c16480bcd refactor(style): Update Eslint to V9 and Prettier to V3 (#21949)
* refactor(style): Update Eslint to V9 and Prettier to V3

* fix: vscode color

* fix: vscode color

* chore: remove Useless dependence and old config file

* chore: format

* Merge branch 'dev' into eslintV9

* fix: fix

* fix: ssr test

* fix: ssr test

* fix: use defineConfig

* fix: prettier format and ignore docs dist

* fix: index.mjs => index.js

* fix: Vscode color

* fix: prettier ignore global.d.ts

* fix: format

---------

Co-authored-by: 2586740555 <15972343+CYJ090915@user.noreply.gitee.com>
2025-09-29 14:14:30 +08:00

101 lines
2.6 KiB
TypeScript

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,
},
}
// eslint-disable-next-line vue/one-component-per-file
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,
}
// eslint-disable-next-line vue/one-component-per-file
const app = createApp({})
const directiveWithInstall = withInstallDirective(
directive,
'test-directive'
)
directiveWithInstall.install?.(app)
expect(app.directive('test-directive')).toBeTruthy()
})
})