2017-09-07 10 views
2

私は上のカバレッジオプションでJestを使用していると私は取得しています:Jest Uncovered Lines - これらの行をどうすればテストできますか?

--------------------------|----------|----------|----------|----------|----------------| 
File      | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines | 
--------------------------|----------|----------|----------|----------|----------------| 
progress-bar.js   |  100 |  75 |  100 |  100 |    17 | 
--------------------------|----------|----------|----------|----------|----------------| 

は、だから私はラインを17発見したが、私はそれらをカバーするかどうかはわかりません。

進捗-bar.js

import ProgressBar from 'progress' 
import isNumber from 'lodash/isNumber' 
import config from '../../config/global' 

function progressBar (total) { 
    if (!isNumber(total)) throw new Error(`progressBar() 'total' arg is not a number.`) 

    const barCfg = config.progressBar 

    const tokens = `${barCfg.bar} ${barCfg.info}` 

    const options = { 
    width: barCfg.width, 
    total: total || 1, 
    complete: barCfg.complete, 
    incomplete: barCfg.incomplete 
    } 

    const bar = new ProgressBar(tokens, options) 

    bar.render() 

    return bar 
} 

export default progressBar 

進捗-bar.test.js

import ProgressBar from 'progress' 
import progressBar from './progress-bar' 

describe('progressBar()',() => { 
    test('returns instanceof ProgressBar',() => { 
    const actual = progressBar(5) instanceof ProgressBar 
    const expected = true 
    expect(actual).toBe(expected) 
    }) 

    test('throw error if arg "total" is not a number',() => { 
    expect(() => { progressBar('moo') }).toThrow() 
    expect(() => { progressBar(null) }).toThrow() 
    }) 

    test('progress bar progress/ticking',() => { 
    const bar = progressBar(5) 
    expect(bar.total).toBe(5) 
    expect(bar.curr).toBe(0) 
    bar.tick() 
    expect(bar.curr).toBe(1) 
    bar.tick() 
    expect(bar.curr).toBe(2) 
    bar.tick() 
    expect(bar.curr).toBe(3) 
    bar.tick() 
    expect(bar.curr).toBe(4) 
    bar.tick() 
    expect(bar.curr).toBe(5) 
    expect(bar.complete).toBe(true) 
    }) 
}) 

だから私は、引数と戻り値をテストしています。

17行を含めて、この機能を完全にテストするにはどうすればよいですか?

答えて

6

[OK]を、私は今、私のダンスの帽子で角に座っています。 https://github.com/istanbuljs/nyc/issues/35#issuecomment-121008298

屋根無し行= 17は、それだけで一つの値を持つリスト覆われていない行の数ですされていない、それは、17行目です:total: total || 1,この発見

test('passing zero forces the default total of 1',() => { 
    const bar = progressBar(0) 
    expect(bar.total).toBe(1) 
}) 
+0

...で固定

私は覆われていない何百万行を持っていたし、依存関係のグラフがJSに狂っていると思った:) – three

関連する問題