微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

伊斯坦布尔分行覆盖是ES6类应该是100%但只有75%

我已经写了一个非常简单的类和一些单元测试.覆盖率报告应为100%,但分行报告为75%.

我无法弄清楚如何达到100%,我应该在哪里看到我所缺少的东西.

UPDATE

单位测试:

/* 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中.

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

jest ./src/ -u

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

解决方法

它与您正在使用的Jest版本以及库使用收集覆盖的方式相关,如果您按照以下步骤,您将找到一个练习示例:

>克隆这个repo https://github.com/a-c-m/react-jest-coverage-test.git
>运行“npm测试”
>查看覆盖率不是100%
用这个命令强制最新版本的jest和babel

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

>看到覆盖现在是100%

希望这将帮助您更新您的配置以获得全面的覆盖.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐