如何在玩笑中获取锚标签的文本

时间:2018-11-09 08:58:38

标签: javascript reactjs jestjs enzyme

  <a href={LinkMappingUtility.getMappedWebUiLink('/#/dashboard')}
    data-id="0"
    className="nav-menu-item"
    autoFocus="true">

  {menuItem({ linkTitle: translate('sbDashboard', currentLanguage), icon: 'swn-home-icon' })}

这是其中的锚标签,我具有菜单项文本,并且我希望文本包含酶

我的代码是:

test(“所有菜单项都显示正确的文本”,()=> {

    const allMenuItemText = [
        { linkTitle: 'Dashboard', icon: 'swn-home-icon' },
        { linkTitle: 'Alerts', icon: 'swn-alerts-icon' },
        { linkTitle: 'Contact Management', icon: 'swn-home-icon'},
        { linkTitle: 'Reporting', icon: 'swn-home-icon' },
        { linkTitle: 'Solutions', icon: 'swn-home-icon' },
        { linkTitle: 'Integrations', icon: 'swn-home-icon' },
        { linkTitle: 'Account Settings', icon: 'swn-home-icon'},
        { linkTitle: 'Support & Training', icon: 'swn-home-icon' }           
    ];

    wrapper.find('.nav-menu-item').forEach((node, index) => {            
        expect(node.text()).toEqual(allMenuItemText[index].linkTitle);       
    })

输出:在这里,我得到了空字符串作为回报

1 个答案:

答案 0 :(得分:2)

我猜只是一个错字,您打算使用类选择器?

  <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
  <script src="https://rawgit.com/RickStrahl/jquery-resizable/master/src/jquery-resizable.js"></script>