New Jul 23, 2026

How do you run a dummy useReducer dispatch function in Jest? [closed]

Libraries, Frameworks, etc. All from Newest questions tagged reactjs - Stack Overflow View How do you run a dummy useReducer dispatch function in Jest? [closed] on stackoverflow.com

I'm currently trying to write unit tests for one of my components, but unfortunately it seems like the dummy dispatch function to take the place of the reducer's one is not firing at all. Up until the final line, everything is working fine, but when the dispatch should fire to make the test pass, it does not.

Am I just missing a step in properly mocking it?

For clarification, in the below, when the date is changed, a new set of radio buttons should be generated and I want to get it to do just that. The component and actual dispatch function work properly outside of this.

test("The error message displays when the date changes after a time is selected", async () => {
    const user = userEvent.setup();
    const handleSubmit = jest.fn();
    const testTimes = ['17:00','17:30','18:30','20:30','21:00','22:00','23:30'];
    const dummyDispatch = () => {
        return {availableTimes: ['00:00']}
    }
    render(<BookingForm availableTimes={testTimes} dispatch={dummyDispatch} />);
    const radioButton = screen.getByRole('radio', { name: /23:30/i });
    expect(radioButton).toBeInTheDocument();
    await user.click(radioButton);
    expect(radioButton).toBeChecked();
    const datePicker = screen.getByLabelText(/Choose date/i);
    fireEvent.change(datePicker, { target: { value: '2026-12-31' } });
    fireEvent.blur(datePicker);

const radioButtonNew = screen.getByRole('radio', { name: /00:00/i }); expect(radioButtonNew).toBeInTheDocument(); //error here, 00:00 is not in the doc });

Scroll to top