测试期间Vue无限循环

菲利普·西格曼特

以下组件最终在测试过程中陷入无限的重新渲染循环中,我不知道为什么。它在应用程序中工作得很好,它所做的就是通过事件总线接收一些数据,将其映射到可以在component标签“ is”属性中使用的东西,并将其推入数组。

<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>

InfoNotificationView并且UserErrorNotificationView是围绕BAlert的简单包装。

以下是导致内存不足异常的测试。

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);
    });
});
 
菲利普·西格曼特

事实证明,问题在于仅打印一个很大的对象,因为successNotificationComponent其中包含vue组件。

我通过testId在测试和检查过程中将a放入通知中来修复它

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

使用循环程序的调度程序时,在测试期间永远不会调用 Observable.create

来自分类Dev

集成测试期间,@ Context为空

来自分类Dev

在Mocha测试期间需要/导入svg

来自分类Dev

在测试期间以编程方式烧瓶登录

来自分类Dev

在单元测试期间利用资源

来自分类Dev

在测试期间更改VMContext属性

来自分类Dev

类测试期间发生NullPointerException

来自分类Dev

Spring集成:测试期间的BindException

来自分类Dev

在性能测试期间存储或记录图

来自分类Dev

在硒测试期间保持登录状态

来自分类Dev

应用测试期间如何访问资源

来自分类Dev

CPU压力测试期间过热并关闭

来自分类Dev

在rspec测试期间如何输入输入?

来自分类Dev

测试期间Django CSRF保护失败

来自分类Dev

运行测试期间 Grails NoClassDefFoundError BuildableCriteria

来自分类Dev

Android UI测试期间“未找到测试”

来自分类Dev

NgRx测试-测试期间订阅回调未更新

来自分类Dev

UI 测试期间的测试对象状态 (iOS)

来自分类Dev

如何在单元测试期间使用 vue-test-utils 和shallowMount 找到elementUi 的组件?

来自分类Dev

DateFormat ParseException仅在单元测试期间

来自分类Dev

如何在猴子测试期间避免锁定屏幕事件

来自分类Dev

Swift:如何在测试期间不加载AppDelegate

来自分类Dev

单元测试期间的Python日志捕获

来自分类Dev

在春季测试期间如何制作CrudRepository接口的实例?

来自分类Dev

在测试期间访问由`beforeAll`设置的值

来自分类Dev

在单元测试期间安装Flask app.config

来自分类Dev

如何避免测试期间已经在进行的$ digest

来自分类Dev

负载测试期间插入时的MongoDB竞争条件

来自分类Dev

购买测试期间Amazon App Tester崩溃(Xamarin)

Related 相关文章

热门标签

归档