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:
Rijk van Zanten
2020-03-12 12:31:36 -04:00
committed by GitHub
parent 7c732579c8
commit 68c625ec79
42 changed files with 260 additions and 119 deletions

View File

@@ -0,0 +1,4 @@
import registerComponent from './register-component';
export { registerComponent };
export default registerComponent;

View 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.

View 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);
});
});

View 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;