The assume-enzyme
module provides a more human readable API and assertion
output when using Enzyme in your test suite.
The module is published to the public npm registry and should be installed a dev dependency.
npm install --save-dev assume-enzyme
Assert that a given value is an enzyme instance.
function Example() {
return (
<div className='hello world'></div>
);
}
wrapper = shallow(<Example />);
assume(wrapper).is.enzyme();
Assert that a given component has the supplied classNames.
function Example() {
return (
<div className='hello world'></div>
);
}
wrapper = shallow(<Example />);
assume(wrapper).to.have.className('hello');
assume(wrapper).to.have.className('world');
Assert that a given wrapper contains a given component. While this method
overrides the default contains
and contain
methods it will still work as
expected as this functionality is only triggered if we're passed in a enzyme
instance.
Assert that a component has a given tag name.
function Example() {
return (
<div className='hello world'></div>
);
}
wrapper = shallow(<Example />);
assume(wrapper).to.have.tagName('div');
Assert that a given input is checked or not.
function Example() {
return (
<input id='hello' defaultChecked />
);
}
wrapper = shallow(<Example />);
assume(wrapper).is.checked();
Assert that a given input is disabled or not.
function Example() {
return (
<input id='hello' disabled />
);
}
wrapper = shallow(<Example />);
assume(wrapper).is.disabled();
Assert that a component has a given set of props assigned to it.
MIT