I have the following situation for React JS. I asked a similar question before and Tried to apply the same method to this:
className={'custom-grid-buttons tran-button enrollment-button'}
onClick={() => {this.props.openBatchUpdateLOAModal()}}
>
Batch Update
</button>
<button
className={'custom-grid-buttons tran-button enrollment-button'}
onClick={() => {this.props.getSelectedLOAs().then(() => {
this.props.selectedLOAs && this.props.selectedLOAs.length > 0 ? this.props.openDownloadLOAModal() : alert('Please select at least one LOA.')})}}
>
Download By Custodian
</button>
Getting the following error: Method “simulate” is meant to be run on 1 node. 0 found instead. I posted most of the test file here but I believe the main error is coming from this line :
wrapper.find(".custom-grid-buttons tran-button enrollment-button").simulate("click");
Pros are all set :
// jest mock functions (mocks this.props.func)
const setFromStatusList = jest.fn();
const openBatchUpdateLOAModal = jest.fn();
const getSelectedLOAs = jest.fn();
const getDynamicRender = jest.fn();
const openDownloadLOAModal = jest.fn();
const onClick = jest.fn();
// defining this.props
const baseProps = {
location: {
pathname:[],
},
services :{
Counterparty :{
URL : "TEST URL",
subscription_key: "test key",
},
},
setFromStatusList,
openBatchUpdateLOAModal,
getSelectedLOAs,
backgroundapp:{},
getDynamicRender,
openDownloadLOAModal,
onClick,
selectedLOAS:[],
}
beforeEach(() => wrapper = shallow(<BrowserRouter><LOA {...baseProps} /></BrowserRouter>));
it("should call openBatchUpdateLOAModal click", () => {
// Reset info from possible previous calls of these mock functions:
baseProps.openBatchUpdateLOAModal.mockClear();
baseProps.getSelectedLOAs.mockClear();
wrapper.setProps({
selectedLOAS: null
});
// Find the button and call the onClick handler
wrapper.find(".custom-grid-buttons tran-button enrollment-button").simulate("click");
// Test to make sure prop functions were called via simulating the button click
expect(baseProps.openBatchUpdateLOAModal).toHaveBeenCalled();
expect(baseProps.getSelectedLOAs).toHaveBeenCalled();