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

前端之家收集整理的这篇文章主要介绍了伊斯坦布尔分行覆盖是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%

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

原文链接:https://www.f2er.com/js/153472.html

猜你在找的JavaScript相关文章