小编Ahm*_*hab的帖子

用悬念测试 Vue3 异步设置组件的正确方法是什么?

毫无疑问,Suspense 功能会带来更干净的代码库,但尽管它很整洁,但它却很难测试。具体来说,它还没有很好的记录。

案件:

VUE CLI 生成的常规应用程序

  • 技术堆栈:Vuex、Router、PWA、用于单元测试的 jest

挑战:

我按照以下建议使用了 Suspense 组件:

    <RouterView name="default" v-slot="{ Component, route }">
      <transition :name="route.meta.transition" mode="out-in" :duration="300" :key="route.path">
        <Suspense >
          <template #default>
            <component :is="Component" :key="route.path"/>
          </template>
          <template #fallback>
            <div class="top-0 right-0 h-screen w-screen z-50 flex justify-center items-center">
               <div class="animate-spin rounded-full h-32 w-32 border-t-2 border-b-2 border-yellow-700"></div>
            </div>
          </template>
        </Suspense>
      </transition>
    </RouterView>

Run Code Online (Sandbox Code Playgroud)

我的路线和观点很少:

  • 其中之一用于登录视图
  // here is the gotcha, if ever I removed async from setup the test runs well otherwise it always returns empty vm.
  async …
Run Code Online (Sandbox Code Playgroud)

javascript ecmascript-6 jestjs vuejs3

2
推荐指数
1
解决办法
3445
查看次数

标签 统计

ecmascript-6 ×1

javascript ×1

jestjs ×1

vuejs3 ×1