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

chore: bump to vue v3.2.34 #1510

Merged
merged 5 commits into from May 20, 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
8 changes: 4 additions & 4 deletions package.json
Expand Up @@ -34,9 +34,9 @@
"@typescript-eslint/eslint-plugin": "^5.25.0",
"@typescript-eslint/parser": "^5.25.0",
"@vue/babel-plugin-jsx": "^1.1.1",
"@vue/compat": "3.2.33",
"@vue/compiler-dom": "3.2.33",
"@vue/compiler-sfc": "3.2.33",
"@vue/compat": "3.2.34",
"@vue/compiler-dom": "3.2.34",
"@vue/compiler-sfc": "3.2.34",
"@vue/vue3-jest": "27.0.0-alpha.4",
"babel-jest": "27.5.1",
"babel-preset-jest": "28.0.2",
Expand All @@ -57,7 +57,7 @@
"tslib": "2.4.0",
"typescript": "4.6.4",
"vitepress": "^0.22.4",
"vue": "3.2.33",
"vue": "3.2.34",
"vue-class-component": "^8.0.0-rc.1",
"vue-jest": "^5.0.0-alpha.10",
"vue-router": "^4.0.15",
Expand Down
27 changes: 27 additions & 0 deletions src/baseWrapper.ts
Expand Up @@ -2,8 +2,12 @@ import { textContent } from './utils'
import type { TriggerOptions } from './createDomEvent'
import {
ComponentInternalInstance,
ComponentOptions,
ComponentPublicInstance,
ComputedOptions,
CreateComponentPublicInstance,
FunctionalComponent,
MethodOptions,
nextTick
} from 'vue'
import { createDOMEvent } from './createDomEvent'
Expand Down Expand Up @@ -99,6 +103,29 @@ export default abstract class BaseWrapper<ElementType extends Node>

// searching by string without specifying component results in WrapperLike object
findComponent<T extends never>(selector: string): WrapperLike
// Find Component Options aka plain object
findComponent<
Props,
RawBindings = any,
D = any,
C extends ComputedOptions = ComputedOptions,
M extends MethodOptions = MethodOptions
>(
selector: ComponentOptions<Props, RawBindings, D, C, M>
): VueWrapper<CreateComponentPublicInstance<Props, RawBindings, D, C, M>>
findComponent<T extends ComponentOptions>(
selector: string
): VueWrapper<
T extends ComponentOptions<
infer Props,
infer RawBindings,
infer D,
infer C,
infer M
>
? CreateComponentPublicInstance<Props, RawBindings, D, C, M>
: VueWrapper<CreateComponentPublicInstance>
>
// searching for component created via defineComponent results in VueWrapper of proper type
findComponent<T extends DefinedComponent>(
selector: T | Exclude<FindComponentSelector, FunctionalComponent>
Expand Down
9 changes: 8 additions & 1 deletion src/mount.ts
Expand Up @@ -20,6 +20,7 @@ import {
EmitsOptions,
ComputedOptions,
ComponentPropsOptions,
ComponentProvideOptions,
ComponentOptions,
ConcreteComponent,
Prop
Expand Down Expand Up @@ -129,6 +130,8 @@ export function mount<
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
E extends EmitsOptions = Record<string, any>,
EE extends string = string,
Provide extends ComponentProvideOptions = ComponentProvideOptions,
RawOptions extends {} = {},
PP = PublicProps,
Props = Readonly<ExtractPropTypes<PropsOrPropOptions>>,
Defaults = ExtractDefaultPropTypes<PropsOrPropOptions>
Expand All @@ -143,6 +146,8 @@ export function mount<
Extends,
E,
EE,
Provide,
RawOptions,
PP,
Props,
Defaults
Expand All @@ -164,6 +169,8 @@ export function mount<
Extends,
E,
EE,
Provide,
RawOptions,
PP,
Props,
Defaults
Expand Down Expand Up @@ -273,7 +280,7 @@ export function mount(
inputComponent: any,
options?: MountingOptions<any> & Record<string, any>
): VueWrapper<any> {
// normalise the incoming component
// normalize the incoming component
const originalComponent = unwrapLegacyVueExtendComponent(inputComponent)
let component: ConcreteComponent
const instanceOptions = getInstanceOptions(options ?? {})
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Expand Up @@ -21,6 +21,7 @@ export interface NameSelector {
export type FindAllComponentsSelector =
| DefinedComponent
| FunctionalComponent
| ComponentOptions
| NameSelector
| string
export type FindComponentSelector = RefSelector | FindAllComponentsSelector
Expand Down
31 changes: 18 additions & 13 deletions test-dts/mount.d-test.ts
Expand Up @@ -56,8 +56,8 @@ mount(AppWithDefine, {
})

expectError(
// @ts-expect-error wrong prop type should not compile
mount(AppWithDefine, {
// @ts-expect-error wrong prop type should not compile
props: { a: 2 }
})
)
Expand Down Expand Up @@ -186,14 +186,12 @@ declare const FunctionalComponentEmit: FunctionalComponent<
level: number
},
{ hello: (foo: string, bar: string) => void }
>
>

mount(FunctionalComponent)
mount(defineComponent(FunctionalComponent))

mount(FunctionalComponentEmit)

// @ts-ignore vue 3.0.2 doesn't work. FIX: https://github.com/vuejs/vue-next/pull/2494
mount(defineComponent(FunctionalComponentEmit))

// class component
Expand All @@ -204,7 +202,7 @@ mount(defineComponent(FunctionalComponentEmit))
}
})
class ClassComponent extends Vue {
dataText: string = ''
dataText = ''
get computedMsg(): string {
return `Message: ${(this.$props as any).msg}`
}
Expand All @@ -224,6 +222,7 @@ class CustomClassComponent<Props extends {} = {}> {
private static __vccValue?: ComponentOptions
static get __vccOpts(): ComponentOptions {
if (this.__vccValue) return this.__vccValue
// eslint-disable-next-line @typescript-eslint/no-this-alias
const CompConstructor = this
return (this.__vccValue = {
name: CompConstructor.name,
Expand Down Expand Up @@ -279,14 +278,20 @@ class WithPropCustomClassComponent extends CustomClassComponent<CustomClassCompo
}

expectError(
// @ts-expect-error should has props error
mount<WithPropCustomClassComponent, CustomClassComponentProps>(WithPropCustomClassComponent, {
props: {}
})
mount<WithPropCustomClassComponent, CustomClassComponentProps>(
// @ts-expect-error should has props error
WithPropCustomClassComponent,
{
props: {}
}
)
)
mount<WithPropCustomClassComponent, CustomClassComponentProps>(
WithPropCustomClassComponent,
{
props: { size: 'small' }
}
)
mount<WithPropCustomClassComponent, CustomClassComponentProps>(WithPropCustomClassComponent, {
props: { size: 'small' }
})

// endregion

Expand All @@ -313,7 +318,6 @@ mount(Foo, {

expectError(
mount(
// @ts-expect-error
defineComponent({
props: {
baz: String,
Expand All @@ -324,6 +328,7 @@ expectError(
}
}),
{
// @ts-expect-error
props: {
baz: 'hello'
}
Expand Down
4 changes: 2 additions & 2 deletions test-dts/shallowMount.d-test.ts
Expand Up @@ -27,8 +27,8 @@ shallowMount(AppWithDefine, {
})

expectError(
// @ts-expect-error wrong prop type should not compile
shallowMount(AppWithDefine, {
// @ts-expect-error wrong prop type should not compile
props: { a: 2 }
})
)
Expand Down Expand Up @@ -97,7 +97,7 @@ wrapper = shallowMount(AppWithoutProps, {
}
})
class ClassComponent extends Vue {
dataText: string = ''
dataText = ''
get computedMsg(): string {
return `Message: ${(this.$props as any).msg}`
}
Expand Down
2 changes: 1 addition & 1 deletion tests/features/compat.spec.ts
Expand Up @@ -3,7 +3,7 @@ import { mount } from '../../src'

jest.mock('vue', () => mockVue)

const { configureCompat, extend, defineComponent, h } = mockVue as any
const { configureCompat, extend, defineComponent, h } = mockVue

describe('@vue/compat build', () => {
describe.each(['suppress-warning', false])(
Expand Down
4 changes: 2 additions & 2 deletions tests/mountingOptions/mocks.spec.ts
Expand Up @@ -38,10 +38,10 @@ describe('mocks', () => {
</div>
`,
computed: {
url() {
url(): string {
return `/posts/${this.$route.params.id}`
},
id() {
id(): string | string[] {
return this.$route.params.id
Comment on lines -41 to 45
Copy link
Member

Choose a reason for hiding this comment

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

Concerned about this change, not 100% sure what's happening here

Copy link
Member

Choose a reason for hiding this comment

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

route.params[key] is typed like this

image

What is your concern?

Copy link
Member Author

Choose a reason for hiding this comment

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

The concern is that we shouldn't have to explicitly specify the type: the inference is somehow broken with V3.2.34

Copy link
Member

Choose a reason for hiding this comment

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

Having to annotate the return type is something is there since V2, but this is not an issue with Vue test utils, is more a concern with Vue 3.2.34 release, all good on test utils IMO

}
},
Expand Down
5 changes: 5 additions & 0 deletions types/compat.d.ts
@@ -1,3 +1,8 @@
declare module '@vue/compat' {
export * from 'vue'
export function extend<T>(options: T): T

export function configureCompat(
option: Record<string, boolean | string | number>
): void
}