2017-05-26 30 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(); 
    }); 
});