2016-10-19 86 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否則您正在測試的是相同的對象在內存中,而不是值。