jest 不会收集 vue 文件的覆盖范围,以防它在脚本中只有 DefineProps 和 DefineEmit

发布于 2025-01-13 21:09:08 字数 1401 浏览 4 评论 0原文

我不确定为什么 Jest 覆盖行为在下面的场景中发生变化,

如果我有如下代码,它不会收集覆盖范围。

<template>
  <Teleport to="body">
    <div v-if="show" class="modal">
      <div class="modal_content">
        <div class="message xxl">
          <slot></slot>
        </div>
        <button class="button button--info" @click="$emit('reset')">
          continue
        </button>
      </div>
    </div>
  </Teleport>
</template>

<script setup>
defineProps({
  show: Boolean,
});
defineEmits(["reset"]);
</script>

未收集覆盖范围

但如果我只是添加一个虚拟控制台语句,它就可以

<template>
  <Teleport to="body">
    <div v-if="show" class="modal">
      <div class="modal_content">
        <div class="message xxl">
          <slot></slot>
        </div>
        <button class="button button--info" @click="$emit('reset')">
          continue
        </button>
      </div>
    </div>
  </Teleport>
</template>

<script setup>
defineProps({
  show: Boolean,
});
console.log("--silent");
defineEmits(["reset"]);
</script>

覆盖范围被收集

对于为什么会发生这样的情况有什么想法吗?

i am not sure why Jest coverage behavior changes in below scenario

it does not collect a coverage if i have code like below.

<template>
  <Teleport to="body">
    <div v-if="show" class="modal">
      <div class="modal_content">
        <div class="message xxl">
          <slot></slot>
        </div>
        <button class="button button--info" @click="$emit('reset')">
          continue
        </button>
      </div>
    </div>
  </Teleport>
</template>

<script setup>
defineProps({
  show: Boolean,
});
defineEmits(["reset"]);
</script>

coverage not collected

but if i just add a dummy console statement it works

<template>
  <Teleport to="body">
    <div v-if="show" class="modal">
      <div class="modal_content">
        <div class="message xxl">
          <slot></slot>
        </div>
        <button class="button button--info" @click="$emit('reset')">
          continue
        </button>
      </div>
    </div>
  </Teleport>
</template>

<script setup>
defineProps({
  show: Boolean,
});
console.log("--silent");
defineEmits(["reset"]);
</script>

coverage get collected

any thoughts on why it is happening like this ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文