I want to simulate the click on button and expect that onclick was called.
current result fails //expect(wrapper.instance().onclick().called).to.be.equal(true) FAILED jsx
const DeselectAll = (props: Props) => (
<div className="deselectall">
<Button
className="deselectall--button"
icon="minus"
onClick={props.clearItems}
text={translate("deselectall")}
/>
</div>
);
test
function MySpy() {
this.calls = 0;
}
MySpy.prototype.fn = function () {
return () => this.calls++;
}
When(/^Deselect all button is clicked$/, function () {
const mySpy = new MySpy();
const mockCallBack = mySpy.fn();
const button = const mySpy = new MySpy();
const mockCallBack = mySpy.fn();
const button = React.createElement(componentName, { onClick:
mountCallBack});
const childBtn = button.find('.whiteboardarea__deselectall--button');
console.log("deselectall button found ??? ==== " + childBtn.exists());
button.props.onClick();
console.log("if it works ==== " + expect(mySpy.calls).to.be.equal(1));
return true;
});