jeff
jeff

Reputation: 1197

How to check an element type with chai?

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');
    });

Upvotes: 2

Views: 2340

Answers (1)

David Losert
David Losert

Reputation: 4802

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.

Upvotes: 2

Related Questions