Skip to content

Commit

Permalink
docs: added typescript documentation to plugins.md (#1796)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcwbr committed Oct 6, 2022
1 parent 77bfbe2 commit 5c59fa2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
19 changes: 16 additions & 3 deletions docs/guide/extending-vtu/plugins.md
Expand Up @@ -6,9 +6,9 @@ functionality.

Some use cases for plugins:

1. Aliasing existing public methods
1. Attaching matchers to the Wrapper instance
1. Attaching functionality to the Wrapper
1. Aliasing existing public methods
2. Attaching matchers to the Wrapper instance
3. Attaching functionality to the Wrapper

## Wrapper Plugin

Expand Down Expand Up @@ -168,6 +168,19 @@ const wrapper = mount(Component, {
})
```

## Using the plugin with TypeScript

To use your custom wrapper plugin with [TypeScript](https://www.typescriptlang.org/) you have to declare your custom wrapper function. Therefore, add a file named `vue-test-utils.d.ts` with the following content:
```typescript
import { DOMWrapper } from '@vue/test-utils';

declare module '@vue/test-utils' {
export class VueWrapper {
findByTestId(testId: string): DOMWrapper[];
}
}
```

## Featuring Your Plugin

If you're missing functionality, consider writing a plugin to extend Vue Test
Expand Down
2 changes: 1 addition & 1 deletion src/baseWrapper.ts
Expand Up @@ -41,7 +41,7 @@ export default abstract class BaseWrapper<ElementType extends Node>
return this.wrapperElement
}

constructor(element: ElementType) {
protected constructor(element: ElementType) {
this.wrapperElement = element
}

Expand Down
10 changes: 6 additions & 4 deletions src/vueWrapper.ts
Expand Up @@ -31,10 +31,12 @@ export class VueWrapper<
$emit: (event: any, ...args: any[]) => void
} & ComponentCustomProperties = ComponentPublicInstance
> extends BaseWrapper<Node> {
private componentVM: T
private rootVM: ComponentPublicInstance | undefined | null
private __app: App | null
private __setProps: ((props: Record<string, unknown>) => void) | undefined
private readonly componentVM: T
private readonly rootVM: ComponentPublicInstance | undefined | null
private readonly __app: App | null
private readonly __setProps:
| ((props: Record<string, unknown>) => void)
| undefined
private cleanUpCallbacks: Array<() => void> = []

constructor(
Expand Down

0 comments on commit 5c59fa2

Please sign in to comment.