mardi 6 novembre 2018

React - Creating [Reducer Test] using [enzyme] + [Jest]. Login action is confusing

Creating [Reducer Test] using [enzyme] + [Jest]. Login action is confusing.

this is my code

describe('IS_LOGIN_USER action', () => {
  it('should handle IS_LOGIN_USER action', () => {
    const { stateBefore, stateAfter, action } = setup(
      {
        isLoggedIn: false,
        items: {}
      },
      {
        isLoggedIn: true,
        items: {
          email: "email",
          exp: 1541424504,
          iat: 1541420904,
          name: "name",
          uid: "uid",
          url: "imageURL"
        }
      },
      isLoginUser()
    );
    expect(reducer(stateBefore, action)).to(stateAfter);
  });
});

this is initialState object

export const initialState = {
    items: {},
    isLoggedIn: false,
    error: null,
    isroom: [],
    peers: [],
    inroom: true,
    webrtc: null,
    roomname: '',
    mute: false,
    length: 0,
    pass: false,
    popopen: false,
    focusid: '',
    focustitle: '',
    aboutValueTitle: '',
    alertMessage: '',
    spinner: false,
    alertBoxBottom: '',
    alertColor: '#3c29aa',
    channelAlertMessage: false,
    loggedPopUp: false,
    deleteAelrt: false,
    ieCehck: '',
    pageReturn: false
};

When you log in, the action changes from [isLoggedIn: false, items: {}] to [isLoggedIn: true, items: {userData}. However, the result is still Fail. But I don't know what went wrong.

I am very sorry that the sentence is not smooth by writing the question as a translation app.

Aucun commentaire:

Enregistrer un commentaire