You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/mount.ts
+33-12Lines changed: 33 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -478,16 +478,35 @@ export function mount(
478
478
if(global?.mocks){
479
479
constmixin=defineComponent({
480
480
beforeCreate(){
481
-
for(const[k,v]ofObject.entries(
482
-
global.mocksas{[key: string]: any}
483
-
)){
484
-
// we need to differentiate components that are or not not `script setup`
485
-
// otherwise we run into a proxy set error
486
-
// due to https://github.com/vuejs/core/commit/f73925d76a76ee259749b8b48cb68895f539a00f#diff-ea4d1ddabb7e22e17e80ada458eef70679af4005df2a1a6b73418fec897603ceR404
487
-
// introduced in Vue v3.2.45
488
-
if(hasSetupState(this)){
489
-
this.$.setupState[k]=v
490
-
}else{
481
+
// we need to differentiate components that are or not not `script setup`
482
+
// otherwise we run into a proxy set error
483
+
// due to https://github.com/vuejs/core/commit/f73925d76a76ee259749b8b48cb68895f539a00f#diff-ea4d1ddabb7e22e17e80ada458eef70679af4005df2a1a6b73418fec897603ceR404
484
+
// introduced in Vue v3.2.45
485
+
if(hasSetupState(this)){
486
+
// add the mocks to setupState
487
+
for(const[k,v]ofObject.entries(
488
+
global.mocksas{[key: string]: any}
489
+
)){
490
+
// we do this in a try/catch, as some properties might be read-only
491
+
try{
492
+
this.$.setupState[k]=v
493
+
// eslint-disable-next-line no-empty
494
+
}catch(e){}
495
+
}
496
+
// also intercept the proxy calls to make the mocks available on the instance
497
+
// (useful when a template access a global function like $t and the developer wants to mock it)
0 commit comments