Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: vuejs/test-utils
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.4.2
Choose a base ref
...
head repository: vuejs/test-utils
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.4.3
Choose a head ref
  • 16 commits
  • 8 files changed
  • 5 contributors

Commits on Nov 14, 2023

  1. publish: v2.4.2

    lmiller1990 committed Nov 14, 2023
    Copy the full SHA
    cbbd9ac View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    e9fe51f View commit details

Commits on Nov 15, 2023

  1. Copy the full SHA
    c5b8907 View commit details
  2. Copy the full SHA
    8e2a9d0 View commit details
  3. Copy the full SHA
    03d6c2c View commit details

Commits on Nov 16, 2023

  1. Copy the full SHA
    ac640bc View commit details
  2. Copy the full SHA
    c91eced View commit details

Commits on Nov 17, 2023

  1. Copy the full SHA
    3e98cdf View commit details

Commits on Nov 18, 2023

  1. Copy the full SHA
    f2be46d View commit details

Commits on Nov 19, 2023

  1. Copy the full SHA
    d5f95cf View commit details

Commits on Nov 22, 2023

  1. Copy the full SHA
    574e82d View commit details

Commits on Nov 23, 2023

  1. Copy the full SHA
    043a2c9 View commit details

Commits on Nov 25, 2023

  1. Copy the full SHA
    b00181b View commit details

Commits on Nov 26, 2023

  1. Copy the full SHA
    0f9bb3e View commit details

Commits on Nov 28, 2023

  1. Copy the full SHA
    2b4f9e8 View commit details
  2. publish: v2.4.3

    lmiller1990 committed Nov 28, 2023
    Copy the full SHA
    b6a8a66 View commit details
Showing with 836 additions and 579 deletions.
  1. +15 −15 package.json
  2. +773 −538 pnpm-lock.yaml
  3. +7 −9 src/mount.ts
  4. +6 −6 src/renderToString.ts
  5. +1 −1 src/vueWrapper.ts
  6. +1 −1 test-dts/mount.d-test.ts
  7. +1 −1 test-dts/shallowMount.d-test.ts
  8. +32 −8 test-dts/wrapper.d-test.ts
30 changes: 15 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vue/test-utils",
"version": "2.4.1",
"version": "2.4.3",
"license": "MIT",
"main": "dist/vue-test-utils.cjs.js",
"unpkg": "dist/vue-test-utils.browser.js",
@@ -32,31 +32,31 @@
"@rollup/plugin-replace": "5.0.5",
"@rollup/plugin-typescript": "11.1.5",
"@types/js-beautify": "1.14.3",
"@types/node": "20.9.0",
"@typescript-eslint/eslint-plugin": "6.10.0",
"@typescript-eslint/parser": "6.10.0",
"@vitejs/plugin-vue": "4.4.1",
"@vitejs/plugin-vue-jsx": "3.0.2",
"@types/node": "20.9.4",
"@typescript-eslint/eslint-plugin": "6.12.0",
"@typescript-eslint/parser": "6.12.0",
"@vitejs/plugin-vue": "4.5.0",
"@vitejs/plugin-vue-jsx": "3.1.0",
"@vitest/coverage-v8": "0.34.6",
"@vue/compat": "3.3.8",
"@vue/compiler-dom": "3.3.8",
"@vue/compiler-sfc": "3.3.8",
"@vue/server-renderer": "3.3.8",
"eslint": "8.53.0",
"eslint": "8.54.0",
"eslint-config-prettier": "9.0.0",
"eslint-plugin-prettier": "5.0.1",
"husky": "8.0.3",
"jsdom": "22.1.0",
"jsdom": "23.0.0",
"jsdom-global": "3.0.2",
"lint-staged": "15.0.2",
"prettier": "3.0.3",
"lint-staged": "15.1.0",
"prettier": "3.1.0",
"reflect-metadata": "0.1.13",
"rollup": "4.3.0",
"rollup": "4.5.1",
"tslib": "2.6.2",
"typescript": "5.2.2",
"typescript": "5.3.2",
"unplugin-vue-components": "0.25.2",
"vite": "4.5.0",
"vitepress": "1.0.0-rc.25",
"vite": "5.0.2",
"vitepress": "1.0.0-rc.31",
"vitest": "0.34.6",
"vue": "3.3.8",
"vue-class-component": "8.0.0-rc.1",
@@ -110,7 +110,7 @@
"url": "git+https://github.com/vuejs/test-utils.git"
},
"homepage": "https://github.com/vuejs/test-utils",
"packageManager": "pnpm@8.10.2",
"packageManager": "pnpm@8.10.5",
"pnpm": {
"peerDependencyRules": {
"ignoreMissing": [
1,311 changes: 773 additions & 538 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

16 changes: 7 additions & 9 deletions src/mount.ts
Original file line number Diff line number Diff line change
@@ -38,12 +38,12 @@ export function mount<
C = T extends ((...args: any) => any) | (new (...args: any) => any)
? T
: T extends { props?: infer Props }
? DefineComponent<
Props extends Readonly<(infer PropNames)[]> | (infer PropNames)[]
? { [key in PropNames extends string ? PropNames : string]?: any }
: Props
>
: DefineComponent,
? DefineComponent<
Props extends Readonly<(infer PropNames)[]> | (infer PropNames)[]
? { [key in PropNames extends string ? PropNames : string]?: any }
: Props
>
: DefineComponent,
P extends ComponentProps<C> = ComponentProps<C>
>(
originalComponent: T,
@@ -54,9 +54,7 @@ export function mount<
ComponentProps<C>,
ComponentData<C> & ComponentExposed<C> & Omit<P, keyof ComponentProps<C>>
>
> & {
LOOL: Exclude<P, ComponentProps<C>>
}
>

// implementation
export function mount(
12 changes: 6 additions & 6 deletions src/renderToString.ts
Original file line number Diff line number Diff line change
@@ -9,12 +9,12 @@ export function renderToString<
C = T extends ((...args: any) => any) | (new (...args: any) => any)
? T
: T extends { props?: infer Props }
? DefineComponent<
Props extends Readonly<(infer PropNames)[]> | (infer PropNames)[]
? { [key in PropNames extends string ? PropNames : string]?: any }
: Props
>
: DefineComponent
? DefineComponent<
Props extends Readonly<(infer PropNames)[]> | (infer PropNames)[]
? { [key in PropNames extends string ? PropNames : string]?: any }
: Props
>
: DefineComponent
>(
originalComponent: T,
options?: ComponentMountingOptions<C> &
2 changes: 1 addition & 1 deletion src/vueWrapper.ts
Original file line number Diff line number Diff line change
@@ -244,7 +244,7 @@ export class VueWrapper<
return nextTick()
}

setProps(props: T['$props']): Promise<void> {
setProps(props: Partial<T['$props']>): Promise<void> {
// if this VM's parent is not the root or if setProps does not exist, error out
if (this.vm.$parent !== this.rootVM || !this.__setProps) {
throw Error('You can only use setProps on your mounted component')
2 changes: 1 addition & 1 deletion test-dts/mount.d-test.ts
Original file line number Diff line number Diff line change
@@ -93,7 +93,7 @@ expectError(
const AppWithArrayProps = {
props: ['a'],
template: ''
}
} as const

// accept props - vm is properly typed
expectType<string>(
2 changes: 1 addition & 1 deletion test-dts/shallowMount.d-test.ts
Original file line number Diff line number Diff line change
@@ -67,7 +67,7 @@ expectError(
const AppWithArrayProps = {
props: ['a'],
template: ''
}
} as const

// accept props
// vm is properly typed
40 changes: 32 additions & 8 deletions test-dts/wrapper.d-test.ts
Original file line number Diff line number Diff line change
@@ -120,25 +120,49 @@ expectType<{ [key: string]: any }>(wrapper.props())
const ComponentWithProps = defineComponent({
props: {
foo: String,
bar: Number,
},
bar: Number
}
})

const propsWrapper = mount(ComponentWithProps);
const propsWrapper = mount(ComponentWithProps)

propsWrapper.setProps({foo: 'abc'})
propsWrapper.setProps({foo: 'abc', bar: 123})
propsWrapper.setProps({ foo: 'abc' })
propsWrapper.setProps({ foo: 'abc', bar: 123 })
// @ts-expect-error :: should require string
propsWrapper.setProps({foo: 123})
propsWrapper.setProps({ foo: 123 })
// @ts-expect-error :: unknown prop
propsWrapper.setProps({badProp: true})
propsWrapper.setProps({ badProp: true })

expectType<string | undefined>(propsWrapper.props().foo)
expectType<number | undefined>(propsWrapper.props().bar)
// @ts-expect-error :: unknown prop
propsWrapper.props().badProp;
propsWrapper.props().badProp

expectType<string | undefined>(propsWrapper.props('foo'))
expectType<number | undefined>(propsWrapper.props('bar'))
// @ts-expect-error :: unknown prop
propsWrapper.props('badProp')

const requiredPropsWrapper = mount(
defineComponent({
props: {
foo: { type: String, required: true },
bar: { type: Number, required: true }
}
}),
{
props: {
foo: 'abc',
bar: 123
}
}
)

requiredPropsWrapper.setProps({
foo: 'abc'
})

requiredPropsWrapper.setProps({
// @ts-expect-error wrong type
foo: 1
})