2017-08-29 4 views
1

私のテストを改善する方法を理解する上で助けが必要ですか?反応成分のテストを改善するには?

私はbranchesのテストを100%までカバーしましたが、statementsテスト、functionsテスト、linesテストをどのようにカバーしましたか?ここ code-coverage-img

そして、私のテストです:

/** 
* Testing our ItemList component 
*/ 
import { shallow } from 'enzyme'; 
import React from 'react'; 
import { BootstrapProvider } from 'bootstrap-styled'; 
import ItemList from '../index'; 

const renderComponent = (props = {}) => shallow(
    <BootstrapProvider> 
    <ItemList {...props} /> 
    </BootstrapProvider> 
); 

describe('<ItemList />',() => { 
    it('should render an <ItemList /> tag',() => { 
    const renderedComponent = renderComponent(); 
    expect(renderedComponent.find('ItemList').length).toBe(1); 
    }); 
}); 

何かアドバイスは歓迎されているが

は、ここで(冗談で提供された)私のコードカバレッジです。

+1

'shallow'の代わりに' render'を使って文をテストする必要があるかもしれません。 – Mihir

答えて

1

まず、this.propsが強調表示されており、デフォルトでclassNameを持つクラスclassNameをコンポーネント内に設定していることがわかります。

あなたはデフォルトclassNameの存在をテストし、また1つを設定しようとしている可能性があり:レンダリング用として

it('should render an <ItemList /> with a className',() => { 
    const renderedComponent = renderComponent({ 
     className:'className-test' 
    }); 
expect(renderedComponent.find('ItemList').hasClass('className-test')).toEqual(true); 
}); 

it('should render an <ItemList /> with a className 'item' by default ',() => { 
    const renderedComponent = renderComponent(); 
expect(renderedComponent.find('ItemList').hasClass('item')).toEqual(true); 
}); 

を、私はあなたがコメントで与えられたアドバイスに従う示唆しています。

関連する問題