Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getActions method doesn't log correct actions #179

Open
Ckbhatia opened this issue May 28, 2021 · 0 comments
Open

getActions method doesn't log correct actions #179

Ckbhatia opened this issue May 28, 2021 · 0 comments

Comments

@Ckbhatia
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant