Skip to content

getActions method doesn't log correct actions #179

@Ckbhatia

Description

@Ckbhatia

getActions method doesn't log correct actions or more than 3 actions.

I am trying to test reducers where I am dispatching reducers constantly.
But, getActions isn't logging actions more than three.

Jest CLI

 [
      { type: 'events/onStart', payload: undefined },
      { type: 'events/onStart', payload: undefined },
      { type: 'events/onEnd', payload: undefined }
    ] actions
    
reducer.spec.js

it('create event data - on success', async () => {
    const expected = [
      onStart(),
      onSuccess(createEventResponsePayload),
      onEnd(),
    ];
    const callback = jest.fn();
    await dispatch(events.createEventData(createEventPayload, callback));
    
    console.log(actions, 'actions');
    
    // expect(actions[0]).toStrictEqual(expected[0]);
    // expect(actions[1]).toStrictEqual(expected[1]);

    expect(callback).toHaveBeenCalledTimes(1);
  });
events.js

const createEventData = (data, callback) => async (dispatch) => {
  try {
    dispatch(eventSlice.actions.onStart());
    const event = await createEvent(data);
    // Invoke callback with args to confirm request success
    if (callback) {
      callback(null, event.id);
    }
    dispatch(getOrganizerEventsData());
    dispatch(eventSlice.actions.onEnd());
    // Returning back data for chatroom
    return eventDataRegardingChatroom(event);
  } catch (err) {
    // Invoke callback with error arg to confirm request failed
    if (callback) {
      callback(err);
    }
    dispatch(eventSlice.actions.onError(err.toString()));
  }
};

const getOrganizerEventsData = () => async (dispatch) => {
  try {
    dispatch(eventSlice.actions.onStart());
    const events = await getOrganizerEvents();
    dispatch(eventSlice.actions.onSuccess(sortEventsWithDateTime(events)));
    dispatch(eventSlice.actions.onEnd());
  } catch (err) {
    dispatch(eventSlice.actions.onError(err.toString()));
  }
};

As you can see, it should log:

onStart, onStart, onSuccess, onEnd, onEnd

Am I correct?

Why isn't loging in this order?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions