The Never-Ending Vue Loop in Testing

I'm facing an issue where the following component gets stuck in an infinite re-render loop during testing, even though it works perfectly fine in the application. The component simply receives some data via an event bus, maps it to something usable in a component tags 'is' property, and then pushes it into an array.

<template>
  <div id="notification-area">
    <div v-for="(component, index) in notificationComponents" :key="index">
      <component
          :is="component.options"
          :notification="component.notification"
      />
    </div>
  </div>
</template>

<script lang="ts">
import {Component, Inject, Vue} from "vue-property-decorator";
import {Notification, UserErrorNotification, InfoNotification} from "@/Notification";
import InfoNotificationView from "@/components/notifications/InfoNotificationView.vue";
import UserErrorNotificationView from "@/components/notifications/UserErrorNotificationView.vue";
import {ComponentOptions, DefaultComputed, DefaultData, DefaultMethods, PropsDefinition} from "vue/types/options";

type VueOptions = ComponentOptions<
    Vue,
    DefaultData<Vue>,
    DefaultMethods<Vue>,
    DefaultComputed,
    PropsDefinition<Record<string, {}>>
  >

interface NotificationComponent {
  options: VueOptions;
  notification: Notification;
}

@Component({})
export default class NotificationArea extends Vue {
  @Inject('eventBus') private eventBus!: Vue;
  private notificationComponents = [] as Array<NotificationComponent>;

  private static asNotificationComponent(notification: UserErrorNotification | InfoNotification): NotificationComponent{
    if (notification instanceof UserErrorNotification) {
      return {options: new UserErrorNotificationView().$options, notification: notification}
    }
    return {options: new InfoNotificationView().$options, notification: notification}

  }

  created() {
    this.eventBus.$on('notification', (notification: UserErrorNotification | InfoNotification) => {
      this.notificationComponents.push(NotificationArea.asNotificationComponent(notification));
    })
  }
}
</script>

Just to provide some context, InfoNotificationView and UserErrorNotificationView are basic wrappers around a BAlert component.

Below is the test case that seems to be causing an out of memory exception:

describe("NotificationArea.vue", () => {
    let wrapper: Wrapper<NotificationArea>;

    beforeEach(() => {
        wrapper = shallowMount(NotificationArea, {
            provide: {
                eventBus: new MockEventBus()
            },
            created() {}
        });
    });

    it("renders the notifications correctly", async () => {
        wrapper.setData({
            notificationComponents: [successNotificationComponent, warningNotificationComponent]
        });
        await wrapper.vm.$nextTick() // <-- Here it hangs.
        const infoNotification = wrapper.find("infonotificationview-stub");
        expect(infoNotification.props('notification')).toBe(successNotificationComponent);
        const userErrorNotification = wrapper.find("usererrornotificationview-stub")
        expect(userErrorNotification.props("notification")).toBe(warningNotificationComponent);
    });
});
 

Answer №1

Upon further investigation, it was discovered that the issue stemmed from jest printing an exceptionally large object due to the inclusion of a vue component in successNotificationComponent.

The problem was resolved by inserting a testId into the notification during testing and verifying its presence.

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

Is there a way to stop query parameters from piling up whenever I adjust the filter settings?

Encountering issues with query param accumulation when selecting a new filter from the dropdown. How can I ensure that the current filter is retained with each change? Below is the select component code snippet : import SelectInput from '@/Components ...

Yarn Plug'n'Play was unable to locate the module during the next build

Currently, I am in the process of developing a Next.js project with yarn's Plug'n'Play feature. In this project, I have created several pages and added various packages, including mathjs: '^10.3.0' to assist me in parsing user inpu ...

Vue JS does not properly display grid-template-areas

Feeling a bit lost as I copied the style from a previous project that worked flawlessly. Currently using VueJS and encountering issues with the grid-area template not displaying properly in the initial app. Despite searching through similar questions, I ha ...

The 'split' property is not found in the type 'string | ArrayBuffer'. The property 'split' is not available in the type 'ArrayBuffer'.ts(2339)

"I need assistance with splitting a base64 audio file. Specifically, I want to extract only the audio data without the 'data:audio/wav;base64' text included. Can someone provide the correct code for this?" “This code snippet is intended for us ...

The NestJS Backend is always being asked by Grafana to access the /api/live/ws endpoint

After successfully setting up Grafana and Grafana Loki with my NestJS Backend, everything seemed to be working fine. However, I started getting a 404 error from my NestJS because Grafana was requesting the /api/live/ws route. Is there a way to disable thi ...

Discover the method for invoking a Javascript function within a Leaflet popup using HTML

Upon clicking on a marker on the leaflet map, I aim to trigger a popup box that contains five elements: Title Description Image Button (Next Image) Button (Previous Image) To achieve this, I attempted to include a custom popup for each feature ...

Is the Vue JS framework compatible with the @google-cloud/speech module?

I've been experimenting with the Google Cloud API Speech-to-Text Node client library and have found it to work quite well. The documentation provided by the official website is very detailed and helpful. However, I encountered some issues when trying ...

Passing props to route.push in Vue with TypeScript does not work as expected

In my application, I have a straightforward structure consisting of a table and a page for creating a new item. To navigate to the create page and pass parameters, I utilize a button on the main page. initNewRow(): void { let someData: string = 's ...

Is it possible to create a combined header/declaration file in Golang within a single file?

My goal is to automatically generate Golang declaration files based on .json data. While with TypeScript I can consolidate types/declarations in one file using namespaces, it seems more complex to achieve the same with Golang packages and namespacing. In ...

What is the best way to create a test for my Vue component using Jest?

Below is the login form component that needs to be tested for various scenarios: Verify successful login with both username and password filled Check for input error when either username or password is left blank Ensure input error is thrown when only us ...

Saving a local JSON file in Angular 5 using Typescript

I am currently working on developing a local app for personal use, and I want to store all data locally in JSON format. I have created a Posts Interface and an array with the following data structure: this.p = [{ posts:{ id: 'hey man&ap ...

The attribute 'loaded' is not found in the 'HttpSentEvent' data type

Currently, I have implemented an Angular HTTP post request with the following parameters: this.http .post<{ body: any }>(environment.api.file.upload, reqBody, { reportProgress: true, observe: 'events', }) .subscribe((ev: HttpE ...

Which option yields better performance: using useSelector() on an object directly or on its individual properties?

Imagine we are currently developing a Customer Profile page within our store, using an object called CustomerProfile. export interface ICustomerProfileState { status: string, customerId: number, contactInfo: IContactInfo, financialInfo: IFi ...

What could be causing the issue with lodash not functioning properly after importing it in Vue.js?

Starting fresh with a new vue.js installation using the "vue create todo --default" command was a smooth process. I then decided to enhance it by installing lodash with the command "npm i --save lodash". Checking my package.json file, I can confirm that lo ...

How to associate an object with a component in Angular2/TypeScript using HTTP

I am currently working on displaying a list of item names retrieved from a REST API. By utilizing the map function on the response observable and subscribing to it, I was able to obtain the parsed items object. Now, my challenge is how to bind this object ...

What is the proper way to expand a TypeScript class?

I'm facing a dilemma with the code snippet below. The line m.removeChild(m.childNodes[0]) is causing an issue with the TypeScript compiler. I'm unsure if childNodes: BaseNode[]; is the correct approach in this scenario. class BaseNode { childNo ...

Encountering an ENOENT error in the CodeSandbox CI environment, whereas this issue does not arise in GitHub

I am currently in the process of creating a GitHub pull request for the react-querybuilder library. However, I am encountering an issue with my CodeSandbox CI job, which is failing and displaying the following error message: { [Error: ENOENT: no such file ...

Convert npm folder structure to JSON format

I am attempting to utilize Dree to retrieve the folder structure as a JSON object. After following this link, I have successfully installed the package: https://www.npmjs.com/package/dree To test it out, I have provided the path to my components folder w ...

Employing async await for postponing the execution of a code block

I have been working on an Angular component where I need to perform some actions after a data service method returns some data asynchronously. Although I attempted to use async/await in my code, I feel that I may not have fully understood how it works. Her ...

The instance is referencing the property or method "sendResetMail" during render, but it is not defined

I'm pretty new to Vue and struggling with an error message while trying to get a reset email modal working in my Vue project: The error says that the property or method "sendResetMail" is not defined on the instance but referenced during render. I ...