您的位置:首页 > Web前端 > React

[React Testing] Reusing test boilerplate

2016-01-07 15:12 681 查看
Setting up a shallow renderer for each test can be redundant, especially when trying to write similar tests that have slight tweaks. In this lesson, we go over how you can reduce some of the overlapping code so that each test only contains the unique pieces of the test.

describe('active class', ()=>{

function renderLikeCounter(isActive){
const renderer = TestUtils.createRenderer();
renderer.render(<LikeCounter count={5} isActive={isActive}/>);
return renderer.getRenderOutput().props.className.includes('LikeCounter--active');
}

it('should have active class based on isActive props: true', ()=>{
expect(renderLikeCounter(true)).toEqual(true);
});

it('should have active class based on isActive props: false', ()=>{
expect(renderLikeCounter(false)).toEqual(false);
});
});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: