我编写了一个非常简单的类和一些单元测试。覆盖率报告应为 100%,但我认为分支机构为 75%。
我不知道如何达到 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 版本以及库收集覆盖率的方式有关,如果您按照以下步骤操作,您将找到一个实践示例:
- 克隆此存储库 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%
希望这将帮助您更新配置以获得全面覆盖。
关于 Istanbul 尔分支覆盖率是 ES6 级别,应该是 100%,但只有 75%,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39446669/