How to check an element type with chai?

我们两清 提交于 2019-12-12 01:36:21

问题


I want to check whether an element is an a or a div, how do I accomplish this?
this code is not working:

it('has no link if required', () => {
        const wrapper = shallow(<AssetOverlay asset={ assetsData[0] } shouldBeLinked />);
        expect(wrapper.find('.overlay-asset-link')).to.be.a('a');

        const wrapper1 = shallow(<AssetOverlay asset={ assetsData[0] } shouldBeLinked="false" />);
        //expect(wrapper1.find('.overlay-asset-link')).to.be.a('div');
    });

回答1:


Well thats because chais type checking checks for javascript types, not for HTML-Tags.

In case wrapper.find() returns a normal HTML-Element, you could achieve what you want to test with:

expect(wrapper.find('.overlay-asset-link').tagName).to.equal('A');

Note: The tagname-property is always uppercase.



来源:https://stackoverflow.com/questions/36618846/how-to-check-an-element-type-with-chai

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!