测试以下功能:sanitizeEmail

时间:2019-05-20 18:38:21

标签: reactjs testing jestjs

尝试测试以下功能以确保其被调用以及其是否正常运行 这是功能:

   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
}

将Jest和酶用于React Js

此刻我的考试

beforeEach(() => wrapper = mount(<MemoryRouter keyLength={0}><ProfileMenuComponent {...baseProps} /></MemoryRouter>));

 it('Test componentDidMount method',() => {
  wrapper.setProps({
    user:{
     Email:""
    }
  })
 wrapper.find('ProfileMenuComponent').setState({
   permissionsLoaded:true,
   localPermissions:{[globals.UI_NOTIFICATION ]:true }
 });
wrapper.update();  

不太确定如何处理以下2条语句:

expect(wrapper.find('ProfileMenuComponent')。instance()。componentDidMount())。toEqual();

expect(wrapper.find('ProfileMenuComponent').state('permissionsLoaded')).toBeTruthy();
 });

0 个答案:

没有答案