Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
fitu-martin opened this issue Sep 4, 2024 · 0 comments
Open

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

fitu-martin opened this issue Sep 4, 2024 · 0 comments

Comments

@fitu-martin
Copy link

fitu-martin commented Sep 4, 2024

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 )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant