Istanbul 尔分支覆盖率是 ES6 级别,应该是 100%,但只有 75%

标签 istanbul es6-class

我编写了一个非常简单的类和一些单元测试。覆盖率报告应为 100%,但我认为分支机构为 75%。

enter image description here

我不知道如何达到 100% 以及我应该在哪里寻找以了解我缺少的内容。

更新

单元测试:

/* global describe jest it expect */

import GenericDice from '../generic-dice-vanilla';

jest.unmock('../generic-dice-vanilla');

describe('GenericDice', () => {
  it('exists.', () => {
    expect(GenericDice).toBeDefined();
  });

  it('has a default face property set to 1', () => {
    const dice = new GenericDice();

    expect(dice.face).toBe(1);
  });

  it('has a default rolling property set to true', () => {
    const dice = new GenericDice();

    expect(dice.rolling).toBe(true);
  });

  it('has a default animation property set to an empty string', () => {
    const dice = new GenericDice();

    expect(dice.animation).toBe('');
  });

  it('outputs something when the render function is called', () => {
    const dice = new GenericDice();
    const result = dice.render();

    expect(result).toBeDefined();
  });
});

我正在使用 Babel.js 将此代码从 ES6 转译为 ES5。

要运行单元测试,我使用以下命令:

开玩笑./src/-u

所有代码可以在Github上找到:https://github.com/gyroscopico/generic-dice/tree/feature/35-vanilla

最佳答案

这与您使用的 Jest 版本以及库收集覆盖率的方式有关,如果您按照以下步骤操作,您将找到一个实践示例:

  1. 克隆此存储库 https://github.com/a-c-m/react-jest-coverage-test.git
  2. 运行“npm 测试”
  3. 查看覆盖率不是 100%
  4. 使用此命令强制使用最新版本的 jest 和 babel

rm -rf node_modules/jest; npm install jest@test babel-jest@test multimatch istanbul-lib-instrument; npm test

  • 现在的覆盖率是 100%
  • 希望这将帮助您更新配置以获得全面覆盖。

    关于 Istanbul 尔分支覆盖率是 ES6 级别,应该是 100%,但只有 75%,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39446669/

    相关文章:

    unit-testing - ReactJS:未经测试文件的 Jest 覆盖率报告显示覆盖率 0%

    javascript - 用于多个脚本的单个 istanbul 命令(或组合覆盖率报告)

    node.js - 使用异步函数模拟请求错误

    javascript - es6 从静态函数访问类构造函数

    javascript - 调用 Javascript 类方法时出现错误 'Can' t find variable'

    javascript - ES6 : Can't Deconstruct inside a call constructor

    node.js - 我可以使用 istanbul 来检测 mocha html-cov

    node.js - 我怎样才能让 Istanbul 尔与 Node 、 Mocha 、 Jasmine 一起工作并需要 js

    javascript - 调用模块函数时注入(inject)的模块未定义

    javascript - 从表中选择一个单元格并为其指定唯一的类