Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added typescript documentation to plugins.md #1796

Merged
merged 1 commit into from Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure this does anything - this class is already abstract so you cannot make an instance of it anyway. Might be good to revert an unnecessary change, unless I'm missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

it was a hint from intelliJ

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