score:5

Accepted answer
import { saveCheckboxInput } from '../../actions/userInputActions';

let store, shallowWrapper;

beforeEach(() => {
    store = mockStore(initialState)
    store.dispatch = jest.fn();
    shallowWrapper = shallow(
      <CheckboxSingle 
         store={store} 
         desc="mockDesc"
         linkId="mockLinkId" 
         relatedLinkIds={["mock1", "mock2"]} 
         stepNumber={1} 
      />
    ).dive();
}); 


test('should call onChange after clicked', () => {
  const action = saveCheckboxInput(
       "mockLinkId", 
       true, 
       "mockDesc", 
       ["mock1", "mock2"], 
       1
  );

  shallowWrapper.find('input[type="checkbox"]')
    .simulate('change', { target: { checked: true } });
  expect(store.dispatch).toHaveBeenCalledWith(action);
});

Related Query

More Query from same tag