Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feature/vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
okxiaoliang4 committed Jul 4, 2022
2 parents f347b92 + 6bab48a commit 93ce9ff
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 58 deletions.
6 changes: 3 additions & 3 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "@vue/test-utils",
"version": "2.0.1",
"version": "2.0.2",
"license": "MIT",
"main": "dist/vue-test-utils.cjs.js",
"unpkg": "dist/vue-test-utils.browser.js",
Expand Down Expand Up @@ -32,7 +32,7 @@
"@types/node": "18.0.0",
"@types/pretty": "^2.0.1",
"@typescript-eslint/eslint-plugin": "^5.30.3",
"@typescript-eslint/parser": "^5.30.0",
"@typescript-eslint/parser": "^5.30.3",
"@vitejs/plugin-vue": "^2.3.3",
"@vitejs/plugin-vue-jsx": "^1.3.10",
"@vue/babel-plugin-jsx": "^1.1.1",
Expand All @@ -59,7 +59,7 @@
"vue": "3.2.37",
"vue-class-component": "^8.0.0-rc.1",
"vue-router": "^4.0.16",
"vue-tsc": "0.35.2",
"vue-tsc": "0.38.2",
"vuex": "^4.0.2"
},
"peerDependencies": {
Expand Down
23 changes: 23 additions & 0 deletions src/mount.ts
Expand Up @@ -57,6 +57,24 @@ const MOUNT_OPTIONS: Array<keyof MountingOptions<any>> = [
'shallow'
]

type ComponentMountingOptions<T> = T extends DefineComponent<
infer PropsOrPropOptions,
any,
infer D,
any,
any
>
? MountingOptions<
Partial<ExtractDefaultPropTypes<PropsOrPropOptions>> &
Omit<
Readonly<ExtractPropTypes<PropsOrPropOptions>> & PublicProps,
keyof ExtractDefaultPropTypes<PropsOrPropOptions>
>,
D
> &
Record<string, any>
: MountingOptions<any>

function getInstanceOptions(
options: MountingOptions<any> & Record<string, any>
): Record<string, any> {
Expand Down Expand Up @@ -172,6 +190,11 @@ export function mount<
>
>
>
// component declared by vue-tsc ScriptSetup
export function mount<T extends DefineComponent<any, any, any, any>>(
component: T,
options?: ComponentMountingOptions<T>
): VueWrapper<InstanceType<T>>

// Component declared with no props
export function mount<
Expand Down
1 change: 1 addition & 0 deletions tests/components/AsyncComponent.vue
@@ -0,0 +1 @@
<script setup lang="ts"></script>
2 changes: 2 additions & 0 deletions tests/components/ComponentWithoutName.vue
@@ -1,3 +1,5 @@
<template>
<div class="ComponentWithoutName">No Name</div>
</template>

<script setup lang="ts"></script>
15 changes: 7 additions & 8 deletions tests/components/Issue1476.vue
Expand Up @@ -4,23 +4,22 @@
<button class="field" @click="selectedField = field">
{{ field.name }}
</button>
<div
v-if="selectedField === field"
class="selectedField"
>
<div v-if="selectedField === field" class="selectedField">
{{ field.name }}
</div>
</template>
</div>
</template>

<script lang="ts">
export default {
import { defineComponent } from 'vue'
export default defineComponent({
props: {
availableFields: { type: Array, required: true }
availableFields: { type: Array as () => any[], required: true }
},
data: () => ({
selectedField: ''
selectedField: '' as any
})
}
})
</script>
6 changes: 4 additions & 2 deletions tests/components/Issue425.vue
Expand Up @@ -7,13 +7,15 @@
</template>

<script lang="ts">
export default {
import { defineComponent } from 'vue'
export default defineComponent({
name: 'MyLink',
props: {
name: {
type: String,
required: true
}
}
}
})
</script>
2 changes: 2 additions & 0 deletions tests/components/ParentComponent.vue
Expand Up @@ -5,3 +5,5 @@
<div>child</div>
</div>
</template>

<script setup lang="ts"></script>
124 changes: 79 additions & 45 deletions yarn.lock
Expand Up @@ -1308,14 +1308,14 @@
semver "^7.3.7"
tsutils "^3.21.0"

"@typescript-eslint/parser@^5.30.0":
version "5.30.3"
resolved "https://registry.npmmirror.com/@typescript-eslint/parser/-/parser-5.30.3.tgz#d288c7dbeadf22403112c773dd53e0700f6dd6d5"
integrity sha512-ddwGEPC3E49DduAUC8UThQafHRE5uc1NE8jdOgl+w8/NrYF50MJQNeD3u4JZrqAXdY9rJz0CdQ9HpNME20CzkA==
dependencies:
"@typescript-eslint/scope-manager" "5.30.3"
"@typescript-eslint/types" "5.30.3"
"@typescript-eslint/typescript-estree" "5.30.3"
"@typescript-eslint/parser@^5.30.3":
version "5.30.4"
resolved "https://registry.npmmirror.com/@typescript-eslint/parser/-/parser-5.30.4.tgz#659411e8700b22c8d5400798ef24838425bf4567"
integrity sha512-/ge1HtU63wVoED4VnlU2o+FPFmi017bPYpeSrCmd8Ycsti4VSxXrmcpXXm7JpI4GT0Aa7qviabv1PEp6L5bboQ==
dependencies:
"@typescript-eslint/scope-manager" "5.30.4"
"@typescript-eslint/types" "5.30.4"
"@typescript-eslint/typescript-estree" "5.30.4"
debug "^4.3.4"

"@typescript-eslint/scope-manager@5.30.3":
Expand All @@ -1326,6 +1326,14 @@
"@typescript-eslint/types" "5.30.3"
"@typescript-eslint/visitor-keys" "5.30.3"

"@typescript-eslint/scope-manager@5.30.4":
version "5.30.4"
resolved "https://registry.npmmirror.com/@typescript-eslint/scope-manager/-/scope-manager-5.30.4.tgz#8140efd2bc12d41d74e8af23872a89f3edbe552e"
integrity sha512-DNzlQwGSiGefz71JwaHrpcaAX3zYkEcy8uVuan3YMKOa6qeW/y+7SaD8KIsIAruASwq6P+U4BjWBWtM2O+mwBQ==
dependencies:
"@typescript-eslint/types" "5.30.4"
"@typescript-eslint/visitor-keys" "5.30.4"

"@typescript-eslint/type-utils@5.30.3":
version "5.30.3"
resolved "https://registry.npmmirror.com/@typescript-eslint/type-utils/-/type-utils-5.30.3.tgz#1bb4efcfc8de38086d50096709b2cccf72684515"
Expand All @@ -1340,6 +1348,11 @@
resolved "https://registry.npmmirror.com/@typescript-eslint/types/-/types-5.30.3.tgz#8ef6313dcec2e297b167dd25ef363e36857c49ff"
integrity sha512-vshU3pjSTgBPNgfd55JLYngHkXuwQP68fxYFUAg1Uq+JrR3xG/XjvL9Dmv28CpOERtqwkaR4QQ3mD0NLZcE2Xw==

"@typescript-eslint/types@5.30.4":
version "5.30.4"
resolved "https://registry.npmmirror.com/@typescript-eslint/types/-/types-5.30.4.tgz#3bc99eca8ba3fcfd6a21480e216b09dab81c3999"
integrity sha512-NTEvqc+Vvu8Q6JeAKryHk2eqLKqsr2St3xhIjhOjQv5wQUBhaTuix4WOSacqj0ONWfKVU12Eug3LEAB95GBkMA==

"@typescript-eslint/typescript-estree@5.30.3":
version "5.30.3"
resolved "https://registry.npmmirror.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.30.3.tgz#d5ff918499dd56039864c157a898b1322d7bff8c"
Expand All @@ -1353,6 +1366,19 @@
semver "^7.3.7"
tsutils "^3.21.0"

"@typescript-eslint/typescript-estree@5.30.4":
version "5.30.4"
resolved "https://registry.npmmirror.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.30.4.tgz#ac4be8a2f8fb1f1c3b346d5992a36163121ddb3f"
integrity sha512-V4VnEs6/J9/nNizaA12IeU4SAeEYaiKr7XndLNfV5+3zZSB4hIu6EhHJixTKhvIqA+EEHgBl6re8pivBMLLO1w==
dependencies:
"@typescript-eslint/types" "5.30.4"
"@typescript-eslint/visitor-keys" "5.30.4"
debug "^4.3.4"
globby "^11.1.0"
is-glob "^4.0.3"
semver "^7.3.7"
tsutils "^3.21.0"

"@typescript-eslint/utils@5.30.3":
version "5.30.3"
resolved "https://registry.npmmirror.com/@typescript-eslint/utils/-/utils-5.30.3.tgz#be2ebaef73e5610c866c4f29ed33669acc89e3fc"
Expand All @@ -1373,6 +1399,14 @@
"@typescript-eslint/types" "5.30.3"
eslint-visitor-keys "^3.3.0"

"@typescript-eslint/visitor-keys@5.30.4":
version "5.30.4"
resolved "https://registry.npmmirror.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.30.4.tgz#b4969df1a440cc999d4bb7f7b7932dce05537089"
integrity sha512-ulKGse3mruSc8x6l8ORSc6+1ORyJzKmZeIaRTu/WpaF/jx3vHvEn5XZUKF9XaVg2710mFmTAUlLcLYLPp/Zf/Q==
dependencies:
"@typescript-eslint/types" "5.30.4"
eslint-visitor-keys "^3.3.0"

"@vitejs/plugin-vue-jsx@^1.3.10":
version "1.3.10"
resolved "https://registry.npmmirror.com/@vitejs/plugin-vue-jsx/-/plugin-vue-jsx-1.3.10.tgz#5b61294ed4334fbc5f5679243fd3ccc448b26044"
Expand All @@ -1390,39 +1424,39 @@
resolved "https://registry.npmmirror.com/@vitejs/plugin-vue/-/plugin-vue-2.3.3.tgz#fbf80cc039b82ac21a1acb0f0478de8f61fbf600"
integrity sha512-SmQLDyhz+6lGJhPELsBdzXGc+AcaT8stgkbiTFGpXPe8Tl1tJaBw1A6pxDqDuRsVkD8uscrkx3hA7QDOoKYtyw==

"@volar/code-gen@0.35.2":
version "0.35.2"
resolved "https://registry.npmmirror.com/@volar/code-gen/-/code-gen-0.35.2.tgz#eb7a573139d0cbaee3d7f38b3362ed6e8838ecaa"
integrity sha512-MoZHuNnPfUWnCNkQUI5+U+gvLTxrU+XlCTusdNOTFYUUAa+M68MH0RxFIS9Ybj4uAUWTcZx0Ow1q5t/PZozo+Q==
"@volar/code-gen@0.38.2":
version "0.38.2"
resolved "https://registry.npmmirror.com/@volar/code-gen/-/code-gen-0.38.2.tgz#1eedaba3a12b9d1954dd99d6745f3f2ede0aca58"
integrity sha512-H81I6d7rZB7teqL+zhK/Xz1v0/kKkUwkB0Aq6b4+BTCqcJeiZkoWxd0gFhrhWTnUoqiM83lhoTGo2vkvx5YagQ==
dependencies:
"@volar/source-map" "0.35.2"
"@volar/source-map" "0.38.2"

"@volar/source-map@0.35.2":
version "0.35.2"
resolved "https://registry.npmmirror.com/@volar/source-map/-/source-map-0.35.2.tgz#7097ca5941b8c01a7fa7f8e66d1195d31c240638"
integrity sha512-PFHh9wN/qMkOWYyvmB8ckvIzolrpNOvK5EBdxxdTpiPJhfYjW82rMDBnYf6RxCe7yQxrUrmve6BWVO7flxWNVQ==
"@volar/source-map@0.38.2":
version "0.38.2"
resolved "https://registry.npmmirror.com/@volar/source-map/-/source-map-0.38.2.tgz#72ccaaa224646da69097abe8360391acd7f042b9"
integrity sha512-DWcYbYt9SPwk0r4VmXk1F0v4X5+hCqH1JRkAWSeJymQyXCQ2OQDEbY2PF12a7y2qn4FUBD2gOba2TynAqI8ZFQ==

"@volar/vue-code-gen@0.35.2":
version "0.35.2"
resolved "https://registry.npmmirror.com/@volar/vue-code-gen/-/vue-code-gen-0.35.2.tgz#770d00706eec85e1e261461d0b6fd13ebe888792"
integrity sha512-8H6P8EtN06eSVGjtcJhGqZzFIg6/nWoHVOlnhc5vKqC7tXwpqPbyMQae0tO7pLBd5qSb/dYU5GQcBAHsi2jgyA==
"@volar/vue-code-gen@0.38.2":
version "0.38.2"
resolved "https://registry.npmmirror.com/@volar/vue-code-gen/-/vue-code-gen-0.38.2.tgz#10b467936cb79edb21e6f91ed25ec3fbe055a4cd"
integrity sha512-whLunD6phSGWBUHZKdTxeglrpzQu26ii8CRVapFdjfyMaVhQ7ESNeIAhkTVyg2ovOPc0PiDYPQEPzfWAADIWog==
dependencies:
"@volar/code-gen" "0.35.2"
"@volar/source-map" "0.35.2"
"@vue/compiler-core" "^3.2.36"
"@vue/compiler-dom" "^3.2.36"
"@vue/shared" "^3.2.36"
"@volar/code-gen" "0.38.2"
"@volar/source-map" "0.38.2"
"@vue/compiler-core" "^3.2.37"
"@vue/compiler-dom" "^3.2.37"
"@vue/shared" "^3.2.37"

"@volar/vue-typescript@0.35.2":
version "0.35.2"
resolved "https://registry.npmmirror.com/@volar/vue-typescript/-/vue-typescript-0.35.2.tgz#e299702c92f2897af7029f8ae685721c0ef13257"
integrity sha512-PZI6Urb+Vr5Dvgf9xysM8X7TP09inWDy1wjDtprBoBhxS7r0Dg3V0qZuJa7sSGz7M0QMa5R/CBaZPhlxFCfJBw==
"@volar/vue-typescript@0.38.2":
version "0.38.2"
resolved "https://registry.npmmirror.com/@volar/vue-typescript/-/vue-typescript-0.38.2.tgz#e9bf7d178755fe2619f43dda499ab1e2a6240a5b"
integrity sha512-5IKvSK2m5yUmH6iu/tNScVlvJGuiHawTfSmjxaMs+/tod25WeK37LEdf+pdKtlJ30bYTQmmkAuEfG01QvvBRGQ==
dependencies:
"@volar/code-gen" "0.35.2"
"@volar/source-map" "0.35.2"
"@volar/vue-code-gen" "0.35.2"
"@vue/compiler-sfc" "^3.2.36"
"@vue/reactivity" "^3.2.36"
"@volar/code-gen" "0.38.2"
"@volar/source-map" "0.38.2"
"@volar/vue-code-gen" "0.38.2"
"@vue/compiler-sfc" "^3.2.37"
"@vue/reactivity" "^3.2.37"

"@vue/babel-helper-vue-transform-on@^1.0.2":
version "1.0.2"
Expand All @@ -1449,7 +1483,7 @@
resolved "https://registry.npmmirror.com/@vue/compat/-/compat-3.2.37.tgz#bd2062a2be88d06046311d5c058aefb17a1d438a"
integrity sha512-MIYkFAz3Fur1mtZBqrNMYTymlohCQ0ol6vtNb58cqExLSCt63xZaXyiZZYPvS6WaMXfbNBDPXMvU9tO922eFCA==

"@vue/compiler-core@3.2.37", "@vue/compiler-core@^3.2.36":
"@vue/compiler-core@3.2.37", "@vue/compiler-core@^3.2.37":
version "3.2.37"
resolved "https://registry.npmmirror.com/@vue/compiler-core/-/compiler-core-3.2.37.tgz#b3c42e04c0e0f2c496ff1784e543fbefe91e215a"
integrity sha512-81KhEjo7YAOh0vQJoSmAD68wLfYqJvoiD4ulyedzF+OEk/bk6/hx3fTNVfuzugIIaTrOx4PGx6pAiBRe5e9Zmg==
Expand All @@ -1459,15 +1493,15 @@
estree-walker "^2.0.2"
source-map "^0.6.1"

"@vue/compiler-dom@3.2.37", "@vue/compiler-dom@^3.2.36":
"@vue/compiler-dom@3.2.37", "@vue/compiler-dom@^3.2.37":
version "3.2.37"
resolved "https://registry.npmmirror.com/@vue/compiler-dom/-/compiler-dom-3.2.37.tgz#10d2427a789e7c707c872da9d678c82a0c6582b5"
integrity sha512-yxJLH167fucHKxaqXpYk7x8z7mMEnXOw3G2q62FTkmsvNxu4FQSu5+3UMb+L7fjKa26DEzhrmCxAgFLLIzVfqQ==
dependencies:
"@vue/compiler-core" "3.2.37"
"@vue/shared" "3.2.37"

"@vue/compiler-sfc@3.2.37", "@vue/compiler-sfc@^3.2.36":
"@vue/compiler-sfc@3.2.37", "@vue/compiler-sfc@^3.2.37":
version "3.2.37"
resolved "https://registry.npmmirror.com/@vue/compiler-sfc/-/compiler-sfc-3.2.37.tgz#3103af3da2f40286edcd85ea495dcb35bc7f5ff4"
integrity sha512-+7i/2+9LYlpqDv+KTtWhOZH+pa8/HnX/905MdVmAcI/mPQOBwkHHIzrsEsucyOIZQYMkXUiTkmZq5am/NyXKkg==
Expand Down Expand Up @@ -1507,7 +1541,7 @@
estree-walker "^2.0.2"
magic-string "^0.25.7"

"@vue/reactivity@3.2.37", "@vue/reactivity@^3.2.36":
"@vue/reactivity@3.2.37", "@vue/reactivity@^3.2.37":
version "3.2.37"
resolved "https://registry.npmmirror.com/@vue/reactivity/-/reactivity-3.2.37.tgz#5bc3847ac58828e2b78526e08219e0a1089f8848"
integrity sha512-/7WRafBOshOc6m3F7plwzPeCu/RCVv9uMpOwa/5PiY1Zz+WLVRWiy0MYKwmg19KBdGtFWsmZ4cD+LOdVPcs52A==
Expand Down Expand Up @@ -1539,7 +1573,7 @@
"@vue/compiler-ssr" "3.2.37"
"@vue/shared" "3.2.37"

"@vue/shared@3.2.37", "@vue/shared@^3.2.36":
"@vue/shared@3.2.37", "@vue/shared@^3.2.37":
version "3.2.37"
resolved "https://registry.npmmirror.com/@vue/shared/-/shared-3.2.37.tgz#8e6adc3f2759af52f0e85863dfb0b711ecc5c702"
integrity sha512-4rSJemR2NQIo9Klm1vabqWjD8rs/ZaJSzMxkMNeJS6lHiUjjUeYFbooN19NgFjztubEKh3WlZUeOLVdbbUWHsw==
Expand Down Expand Up @@ -3973,12 +4007,12 @@ vue-router@^4.0.16:
dependencies:
"@vue/devtools-api" "^6.0.0"

vue-tsc@0.35.2:
version "0.35.2"
resolved "https://registry.npmmirror.com/vue-tsc/-/vue-tsc-0.35.2.tgz#85b94027bebc0c6834e0c20b337900468d83b28d"
integrity sha512-aqY16VlODHzqtKGUkqdumNpH+s5ABCkufRyvMKQlL/mua+N2DfSVnHufzSNNUMr7vmOO0YsNg27jsspBMq4iGA==
vue-tsc@0.38.2:
version "0.38.2"
resolved "https://registry.npmmirror.com/vue-tsc/-/vue-tsc-0.38.2.tgz#89175a6bb9a8b5724e84ab5d63dc5113041c5bfa"
integrity sha512-+OMmpw9BZC9khul3I1HGtWchv7BCiaM7NvfdilVAiOFkjnivIoaW6jJm6YPQJaEPouePtpkDUWovyzgNxWdDsw==
dependencies:
"@volar/vue-typescript" "0.35.2"
"@volar/vue-typescript" "0.38.2"

vue@3.2.37, vue@^3.2.33:
version "3.2.37"
Expand Down

0 comments on commit 93ce9ff

Please sign in to comment.