0

As per the title of the question.

.../selector.js

const makeSelectUserData = () => createSelector(
  selectProfile,
  (profileState) => profileState.get('userData')
);

.../tests/selectors.test.js

it('should select the current user', () => {
    const mockedState = fromJS({
      profile: {
        userData: {
          firstName: "X",
          lastName: "Y",
          gender: "Male",
          email: "a@b.cd",
        },
      },
    });
    console.log(userDataSelector(mockedState));
    expect(userDataSelector(mockedState)).toEqual(user);
  });

console.log ... prints:

Map { "firstName": "X", "lastName": "Y", "gender": "Male", "email": "a@b.cd" }

hence why, but I don't get why other selector where user is a string (for example) just work and the selector returns a string as it should.

Strangely enough, the selector actually behaves correctly, but the test doesn't.

dragonmnl
  • 14,578
  • 33
  • 84
  • 129

1 Answers1

0

I found the solution.

All that was necessary was to chance expect(...

to

expect(userDataSelector(mockedState).toJS()).toEqual(user);

since fromJS() transforms an object to an immutable which is still returned as such by the selector.

The other tests with native (primitive) values still worked because immutable doesn't alter them

dragonmnl
  • 14,578
  • 33
  • 84
  • 129