mirror of
https://github.com/directus/directus.git
synced 2026-02-04 09:34:56 -05:00
Document and structure utils / compositions (#168)
* Document and structure utils / compositions * Fix tests * Ignore tests in sonar cloud? * Please sonar don't use my test files
This commit is contained in:
4
src/utils/register-component/index.ts
Normal file
4
src/utils/register-component/index.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
import registerComponent from './register-component';
|
||||
|
||||
export { registerComponent };
|
||||
export default registerComponent;
|
||||
13
src/utils/register-component/readme.md
Normal file
13
src/utils/register-component/readme.md
Normal file
@@ -0,0 +1,13 @@
|
||||
# `registerComponent`
|
||||
Registers a component into the global Vue context.
|
||||
|
||||
## Usage
|
||||
```js
|
||||
registerComponent('v-button', VButton);
|
||||
```
|
||||
|
||||
## Vue.component() vs registerComponent()
|
||||
`registerComponent` internally calls `Vue.component()` directly, and doesn't do anything else. The
|
||||
function is purely to extend the accepted TypeScript type for the second parameter. Vue accepts the
|
||||
second parameter to be of type `Component`, yet it's `Vue.component()` function doesn't actually have
|
||||
that type in it's definition.
|
||||
15
src/utils/register-component/register-component.test.ts
Normal file
15
src/utils/register-component/register-component.test.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import Vue, { Component } from 'vue';
|
||||
import registerComponent from './register-component';
|
||||
|
||||
describe('Utils / Register Component', () => {
|
||||
it('Calls Vue.component with the given arguments', () => {
|
||||
const spy = jest.spyOn(Vue, 'component');
|
||||
const component: Component = {
|
||||
render(h) {
|
||||
return h('div');
|
||||
}
|
||||
};
|
||||
registerComponent('test', component);
|
||||
expect(spy).toHaveBeenCalledWith('test', component);
|
||||
});
|
||||
});
|
||||
11
src/utils/register-component/register-component.ts
Normal file
11
src/utils/register-component/register-component.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import Vue, { Component } from 'vue';
|
||||
|
||||
function registerComponent(id: string, component: Component): void;
|
||||
function registerComponent(id: string, component: Parameters<typeof Vue.component>[1]): void;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
function registerComponent(id: string, component: any) {
|
||||
Vue.component(id, component);
|
||||
}
|
||||
|
||||
export { registerComponent };
|
||||
export default registerComponent;
|
||||
Reference in New Issue
Block a user