Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to compare Immutable-js objects

I'm trying to understand why my simple chai (using chai-immutable) test fails.

it('should work', () => {
   var currentState = Immutable.fromJS({
     name: 'myName',
     age: 20,
     friends: []
   });

   var newState = currentState.merge({
     name: 'someOtherName',
     age: 30
   });

   expect(newState).to.equal(Immutable.fromJS({
     name: 'someOtherName',
     age: 30,
     friends: []
   }));
});
  • If I'm using mergeDeep instead of merge - it still doesn't work
  • If I compare the .toJS() eveluation of both expected and actual values (using lodash isEqual) - It works...

What am I doing wrong? I guess I'm missing something stupid...

Thanks, Amit.

like image 235
Amit Kaspi Avatar asked Mar 13 '23 18:03

Amit Kaspi


1 Answers

Try comparing the two with Immutable.is():

let checkThis = Immutable.fromJS({
   name: 'someOtherName',
   age: 30,
   friends: []
 });
Immutable.is(newState, checkThis)//true
like image 112
tome Avatar answered Mar 24 '23 21:03

tome