Ad

Jest Shallow Render Find By Class Excluding

- 1 answer

I am testing a class like:

const wrapper = shallow(<Features {...props}/>);
expect(wrapper.find('.Feature__Item:not(.Feature__Showmore)').length).toBe(2);

But, I am getting an error like this: Error: Enzyme::Selector does not support pseudo-element or pseudo-class selectors.

How can I work around this limitation?

Update: Interesting observation, when I wrote the following in the debug console: wrapper.find('.Feature__Item').findWhere(a => a.hasClass('Feature__Showmore') === false).length

The output was:

0:Object {nodeType: "host", type: "li", props: Object, …}
1:Object {nodeType: "function", type: , props: Object, …}
2:Object {nodeType: "host", type: "li", props: Object, …}
3:Object {nodeType: "function", type: , props: Object, …}
Ad

Answer

I found another way which did the trick:

expect(wrapper.find('.Feature__Item').not('.Feature__Showmore').length).toBe(2);
Ad
source: stackoverflow.com
Ad