2016-10-19 82 views
1

我使用摩卡和柴做一些前端测试,并在下面的断言。摩卡柴意外断言测试错误从对象等于对象

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: '[email protected]', 
     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: '[email protected]', 
     notes: 'Most original name ever' 
     } 
    }); 
    }); 

但是,我仍然得到错误:

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

这是怎么回事?

回答

2

您必须使用to.deep.equal否则您正在测试的是相同的对象在内存中,而不是值。