Skip to content

Unable to get 100% branches coverage, always missing 1 branch #564

Open
@fitu-martin

Description

@fitu-martin

Why I cannot achieve the 100% coverage of branches?

image

I don't know what I'm missing here.

Component.

<template>
  <div class="row">
    <div class="columns small-24">
    </div>
  </div>
</template>

<script>
export default {
  name: 'IndexOnline'
}
</script>

Test file

import { shallowMount } from "@vue/test-utils";
import OnlinePage from "../../../modules/online/views/OnlinePage.vue";

describe("Test suite OnlinePage component", () => {
  let wrapper;

  beforeEach(() => {
    wrapper = shallowMount(OnlinePage, {
    });
  });

  test("should exist element defined", () => {
    expect(wrapper.element).toBeDefined();
  });
});

image

My setup

// package.json
"vue": "^2.7.14",
"jest": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
"babel-jest": "^29.5.0",
"@vue/vue2-jest": "^29.2.3",  // instead of vue-jest

// jest.config.js
testEnvironment: "jsdom",

I also tried to add some methods and logic to the component and still in those cases I'm unable to achieve 100%. There's always a missing branch.

// Component
<template>
  <div v-if="showContent">Content</div>
  <div v-else>No Content</div>
</template>

<script>
export default {
  data() {
    return {
      showContent: true
    };
  }
}
</script>
// Test file
import { shallowMount } from "@vue/test-utils";
import OnlinePage from "../../../modules/online/views/OnlinePage.vue";

describe("Test suite OnlinePage component", () => {
  let wrapper;

  beforeEach(() => {
    wrapper = shallowMount(OnlinePage, {
    });
  });

  test("should show content when showContent is true", () => {
    expect(wrapper.find('div').text()).toBe('Content');
  });

  test("should not show content when showContent is false", async () => {
    await wrapper.setData({ showContent: false });
    expect(wrapper.find('div').text()).toBe('No Content');
  });
});
// Report
Statements   : 100% ( 13/13 )
Branches     : 75% ( 3/4 )
Functions    : 100% ( 2/2 )
Lines        : 100% ( 13/13 )

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions