Skip to content

Latest commit

 

History

History
33 lines (19 loc) · 851 Bytes

hasClass.md

File metadata and controls

33 lines (19 loc) · 851 Bytes

.hasClass(className) => Boolean

Returns whether or not the wrapped node has a className prop including the passed in class name. It must be a single-node wrapper.

Arguments

  1. className (String | RegExp): A single class name or a regex expression.

Returns

Boolean: whether or not the wrapped node has found the class name.

Examples

const wrapper = mount(<MyComponent />);
expect(wrapper.find('.my-button').hasClass('disabled')).to.equal(true);
// Searching using RegExp works fine when classes were injected by a jss decorator
const wrapper = mount(<MyComponent />);
expect(wrapper.find('.my-button').hasClass(/(ComponentName)-(other)-(\d+)/)).to.equal(true);

Common Gotchas

  • .hasClass() expects a class name, NOT a CSS selector. .hasClass('.foo') should be .hasClass('foo')