Jest encounters a TypeError when interacting with Bootstrap-Vue

I am currently utilizing Bootstrap-Vue ^2.23.1 along with Vuejs and vue/compat ^3.2.45, and my testing library is jest ^29.3.1.

However, when I include the BootstrapVue plugin in my tests, it triggers the following error:

TypeError: Cannot read properties of undefined (reading '$bvConfig')

I have attempted using @vue/test-utils and @testing-library/vue without success. It seems likely that the issue is related to BV lacking proper support for Vue 3. Is there a workaround to resolve this error?

@vue/test-utils:

test("component is visible: ", () => {
    const wrapper = mount(
        AccountingTable,
        {
            global: { plugins: [pinia, i18n, BootstrapVue] },
        },
    );
    expect(wrapper.isVisible()).toBeTruthy();
});

@testing-library/vue:

test("component is visible: ", () => {
    const wrapper = render(
        AccountingTable,
        {
            global: { plugins: [pinia, i18n, BootstrapVue] },
        },
    );
    expect(wrapper.isVisible()).toBeTruthy();
});

Here is my jest configuration:

/** @type {import('jest).Config} */
module.exports = {
    preset: "ts-jest",
    testEnvironment: "jsdom",
    testEnvironmentOptions: {
       customExportConditions: ["node", "node-addons"],
    },
    testMatch: ["**/**/*.test.ts"],
    verbose: true,
    moduleNameMapper: {
        '\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': '<rootDir>/mocks/file.mock.js',
    },
    transform: {
        "^.+\\.vue$": "@vue/vue3-jest",
    },
};

Answer №1

I found this solution to be very effective

import { BootstrapVuePlugin } from "bootstrap-vue";

function initializeApp() {
  return shallowMount(App, {
    global: {
        plugins: [BootstrapVuePlugin]
    }
  });
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Having trouble with i18n types not functioning correctly in Typescript and Nuxt?

I am currently utilizing NuxtJS/i18n with TypeScript and have included its types in my TS config: { "compilerOptions": { "types": [ "@nuxt/types", "@nuxtjs/i18n", ] } } However, when attempti ...

Exploring Typescript for Efficient Data Fetching

My main objective is to develop an application that can retrieve relevant data from a mySQL database, parse it properly, and display it on the page. To achieve this, I am leveraging Typescript and React. Here is a breakdown of the issue with the code: I h ...

After filtering the array in JavaScript, perform an additional process as a second step

My task involves manipulating an array through two methods in sequence: Filter the array Then, sort it The filter method I am using is as follows: filterArray(list){ return list.filter(item => !this.myCondition(item)); } The sort method I a ...

Swapping out the initial icon in a v-list-item with Vuetify

I have a list of items with icons that need to change when clicked. The issue I am facing is that all icons are changing at once because they share the same v-model. How can I modify my code so that only the icon being clicked changes? Here is my current i ...

Eliminating the standard padding on a Vuetify v-app-bar

When using Vuetify's v-app-bar, there are default css classes named v-toolbar__content and v-toolbar__extension that apply padding of 16px on the x-axis and 4px on the y-axis, which I aim to eliminate. I attempted to override these classes in my CSS ...

The UploadFile Interface seems to be missing

Can someone clarify whether the @UploadedFile decorator's interface is predefined or if I need to define it myself? ...

Exploring vuelidate: demonstrating personalized validation messages alongside pre-built validators

I'm currently utilizing the vuelidate library to validate my forms. I've been attempting to use the built-in validators along with a custom message, as shown below. However, I have encountered issues with it not functioning properly. For referenc ...

Rule of authentication using Firebase Database

I need to establish a rule in my Firebase Database to prevent unauthorized access for reading and writing purposes. Within my database, there is a collection of words, each containing a "uid" field that corresponds with the uid of the authUser key stored ...

Observable dataset

I'm curious about the correct type of Observables array. Can you advise? So far, I've attempted the following: let myObservables: Observable[] = new Array(); let myObservables: Observable<Array<any>> = new Array(); let myObservables ...

reusable angular elements

I'm facing a situation where I have a search text box within an Angular component that is responsible for searching a list of names. To avoid code duplication across multiple pages, I am looking to refactor this into a reusable component. What would b ...

What distinguishes between the methods of detecting falsy and truthy values?

While working with JavaScript / Typescript, I often find myself needing to verify if a length exists or if a value is true or false. So, the main query arises: are there any differences in performance or behavior when checking like this... const data = [ ...

I am encountering an error stating "Cannot locate module 'nestjs/common' or its related type declarations."

I am currently working on a controller in NestJS located in the file auth.controller.ts. import { Controller } from 'nestjs/common'; @Controller() export class AppController {} However, I encountered an error that says: Error TS2307: Cannot fin ...

I aim to display interconnected information from various APIs in a cohesive manner

I am working with two APIs: component.ts ngOnInit(): void { this.getQueryCountriesList().subscribe(arg => { this.countryDatas = arg; }); this.getQueryNights().subscribe(obj => { this.nightDatas = obj; }); ...

Why do referees attempt to access fields directly instead of using getters and setters?

I am facing an issue with my TypeScript class implementation: class FooClass { private _Id:number=0 ; private _PrCode: number =0; public get Id(): number { return this._Id; } public set Id(id: number) { this._Idprod ...

VueJS and Vite: Encountering an unexpected character '�' while attempting to import files that are not JavaScript. Keep in mind that plugins are required for importing such files

I'm puzzled by the error message I'm receiving: [commonjs--resolver] Unexpected character '�' (Note that you need plugins to import files that are not JavaScript) file: /..../..../WebProjects/..../ProjectName/node_modules/fsevents/fse ...

Add a choice to the select2 directive in Vue 2 and set it as the default selected value

A custom select2 directive has been implemented in Vue 2 as follows: // Custom Select2 directive import Vue from "vue"; function updateSelect (el, binding) { setTimeout(() => { Vue.nextTick(function () { let options = bindin ...

Implementing a Cancel Button in a Form Using Vue.js Bootstrap-Vue

I am trying to implement a cancel button in my code, similar to the reset button functionality, however, the method is not being triggered and the validation for required fields is still taking place. In my NewUser.vue file, I have added the @cancel="onCa ...

Unable to verify Angular 5 identity

After authentication, the application should redirect to another page. However, despite successful authentication according to the logs, the redirection does not occur. What could be causing this issue? auth.guard.ts: import { Injectable } from &apos ...

Load Angular component on demand with necessary dependencies

Searching for an elegant solution (without resorting to private APIs) to create a widget-style dashboard. The goal is to dynamically load components based on user role. Is there a way to import a component and its dependencies included in the component&ap ...

Unlocking the full potential of Vue-FontAwesome: A step-by-step guide to importing both Free and Pro Icons without

I have possession of a FontAwesome Pro License and I am utilizing the Vue-FontAwesome Component. Whenever attempting to import icons from both the free and Pro repositories, an "Duplicate declaration error ..." occurs. Changing the declaration name result ...