I'm trying to set up unit testing for my Vue application.
I'm using Jest. I have mounted a component and I want to run tests on it. This component uses a global function (Vue.prototype), called aao, which fails to run in my tests.
Error message:
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>
example.spec.ts:
import editUser from '@/components/forms/editUser.vue';
import TestComponent from '@/pages/user/UserMyProfile.vue';
import { shallowMount } from '@vue/test-utils';
import { expect } from 'chai';
import 'jest';
describe('AppLoadingScreen', () => {
let component;
beforeEach(() => {
component = shallowMount(TestComponent);
});
it('should render Spinner on mount', () => {
expect(component.find(editUser).exists()).to.be.true;
});
});
AAO function:
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;
How can I make sure that the test utils knows about this.$aao?