Javascript Jest抛出有关缺少全局函数的错误(vue.prototype)

Javascript Jest抛出有关缺少全局函数的错误(vue.prototype),javascript,vue.js,jestjs,Javascript,Vue.js,Jestjs,我正在尝试为我的Vue应用程序设置单元测试 我在开玩笑。我已经安装了一个组件,我想在上面运行测试。该组件使用一个名为aao的全局函数(Vue.prototype),该函数无法在我的测试中运行 错误消息: console.error node_modules/vue/dist/vue.runtime.common.dev.js:621 [Vue warn]: Error in beforeMount hook: "TypeError: this.$aao is not a functio

我正在尝试为我的Vue应用程序设置单元测试

我在开玩笑。我已经安装了一个组件,我想在上面运行测试。该组件使用一个名为aao的全局函数(Vue.prototype),该函数无法在我的测试中运行

错误消息:

console.error node_modules/vue/dist/vue.runtime.common.dev.js:621
[Vue warn]: Error in beforeMount hook: "TypeError: this.$aao is not a function"

found in

---> <MyProfile>
       <Root>
AAO功能:

export function dbRequest(
    method: 'get' | 'put' | 'post' | 'delete',
    endpoint: string,
    data: any,
    headers?: any,
    responseType?: 'blob' | 'json'
) {
    return new Promise<any>((resolve, reject) => {
        ...
    });
}
Vue.prototype.$aao = dbRequest;
导出函数dbRequest(
方法:“获取”|“放置”|“发布”|“删除”,
端点:字符串,
数据:任何,
标题?:任何,
响应类型?:“blob”|“json”
) {
返回新承诺((解决、拒绝)=>{
...
});
}
Vue.prototype.$aao=dbRequest;
如何确保测试UTIL知道这一点。$aao?

已解决

将我的.spec.ts文件更改为.spec.js,并将内容更改为以下内容:

import { mount, createLocalVue, shallowMount } from '@vue/test-utils';
import * as All from 'quasar';  
import dbRequest from 'src/boot/aao';  

const { Quasar, date } = All;

const components = Object.keys(All).reduce((object, key) => {
    const val = All[key];
        if (val && val.component && val.component.name != null) {
        object[key] = val;
    }
    return object;
}, {}); 

describe('Mount Quasar', () => {
    const localVue = createLocalVue();
    localVue.use(Quasar, { components });
    // Here's the solution, the global functions need to be used by the local vue component
    localVue.use(dbRequest);

    const wrapper = mount(UserMyProfile, {
        localVue,
    });
    const vm = wrapper.vm;
    // Tests here
}
请在此处阅读更多信息:

import { mount, createLocalVue, shallowMount } from '@vue/test-utils';
import * as All from 'quasar';  
import dbRequest from 'src/boot/aao';  

const { Quasar, date } = All;

const components = Object.keys(All).reduce((object, key) => {
    const val = All[key];
        if (val && val.component && val.component.name != null) {
        object[key] = val;
    }
    return object;
}, {}); 

describe('Mount Quasar', () => {
    const localVue = createLocalVue();
    localVue.use(Quasar, { components });
    // Here's the solution, the global functions need to be used by the local vue component
    localVue.use(dbRequest);

    const wrapper = mount(UserMyProfile, {
        localVue,
    });
    const vm = wrapper.vm;
    // Tests here
}