React Js-单元测试-sanitizeEmail

时间:2019-07-16 15:42:35

标签: jestjs enzyme

使用ReactJS玩笑和酶进行单元测试。我不确定如何正确测试以下内容:

sanitizeEmail = (email) => {
let result = email;
if(result.indexOf('@') !== -1 && result.substring(0,result.indexOf('@')).length > 3 ) {
  let end = result.indexOf('@');
  let temp = '';
  for(let i in result.substring(4,end)) {
    temp = temp + '*';
  }
  result = result.substring(0,3) + temp + result.substring(end, result.length);
}
return result
}

我想确保此函数被调用,目前正在通过测试,但不影响其覆盖范围 这是我目前的测试

it('Test sanitizeEmail function',() => {
  wrapper.setProps({})
  wrapper.find('CLASSNAME').setState({
  permissionsLoaded:true,
 localPermissions:{[globals.UI_NOTIFICATION ]:true }
});
wrapper.update();
expect(wrapper.find('CLASSNAME').instance().sanitizeEmail('test')).toEqual('test');
expect(wrapper.find('CLASSNAME').state('permissionsLoaded')).toBeTruthy();
});

0 个答案:

没有答案