2017-05-26 23 views
2

我創建集成測試的組件,以測試它的接口,我安裝它像這樣酶檢查是否安裝沒有錯誤的道具類型的組件

const wrapper = shallow(<Component boolVal={()=>{}} /> 

Component我已標記boolVal道具爲布爾值並在安裝時,我收到預期的警告:

`Warning: Failed prop type: Invalid prop `boolVal` of type `function` supplied to `Component`, expected `boolean`.` 

這是正確的,但我想測試失敗。

我該如何歸檔?

+1

您可以檢查如何反應本身[測試](https://github.com/facebook/react/blob/8ba820a699ed337cf4f42a5743313cb925b6f97b/src/isomorphic/classic/types/__tests__/ ReactPropTypes-test.js#L28)這個功能。把一個間諜放在'console.error()'上。 –

回答

0

根據德米特里的回答,這裏是一個在console.error間諜的測試。當道具失敗測試驗證失敗:

describe.only('Test Component',() => { 

    const sandbox = sinon.sandbox.create(); 

    beforeEach(function() { 
     sandbox.spy(console, 'error'); 
    }); 

    it('mounts', function() { 
     shallow(
      <Component boolVal={()=>{}} /> 
     ); 
     assert.isFalse(console.error.called); 
    }); 

    afterEach(function() { 
     sandbox.restore(); 
    }); 
}); 
相關問題