1

I'm using Mocha and Chai to do some front end testing and put in the below assertion.

  it('AddContact returns contact with type = ADD_CONTACT', function () {
    function hi() {return {
      type: 'ADD_CONTACT',
      data: {
        firstName: 'John',
        lastName: 'Doe',
        dateOfBirth: '1/2/89',
        phone: '123-456-7890',
        email: 'jdoe@gmail.com',
        notes: 'Most original name ever'
      }}}
    expect(hi()).to.equal({
      type: 'ADD_CONTACT',
      data: {
        firstName: 'John',
        lastName: 'Doe',
        dateOfBirth: '1/2/89',
        phone: '123-456-7890',
        email: 'jdoe@gmail.com',
        notes: 'Most original name ever'
      }
    });
  });

However, I still get the error:

  AssertionError: expected { Object (type, data) } to equal { Object (type, data) }
  + expected - actual

What's going on?

stackjlei
  • 9,485
  • 18
  • 65
  • 113

1 Answers1

3

You have to use to.deep.equal else you are testing that's the same object in memory, not the value.

Boris Charpentier
  • 3,515
  • 25
  • 28