2016-11-19 35 views
1

spyOn(service,someMethod).and.callThrough();茉莉spyOn不考慮角crubbins

然後...

var an_object = some_objects[0]; 
useADirectiveThatRepeatsOver(some_objects); 

expect(service.someMethod).toHaveBeenCalledWith(an_object); 

失敗

Expected spy someMethod to have been called with [ Object({ 
    sent_date: '2016-11-18T12:06:29.712318Z', 
    email: '[email protected]', url: '/api/v1/invites/1/' }) ] 
    but actual calls were [ Object({ 
    sent_date: '2016-11-18T12:06:29.712318Z', 
    email: '[email protected]', url: '/api/v1/invites/1/', 
    $$hashKey: 'object:110' }) ]. 

的指令:

<div ng-repeat="obj in some_objects"> 
    <span ng-click="someControllerMethod(obj)">{{ obj.email }}</span> 
</div> 

問題,AFAICT,發生在someControllerMethod(OBJ)被稱作 - 外該方法(例如就在obj沒有$$ hashkey之前,但是一旦調用someControllerMethod(),obj就已經獲得了錯誤的關鍵。

我假設沒有辦法防止角度做它做什麼,那麼有什麼辦法可以緩解這種情況?顯然,我不能使用angular.equals()而不是toEqual(),因爲toHaveBeenCalledWith()方法沒有公開方法來改變比較器。

回答

0

原來這可以通過以下方式解決:

<div ng-repeat="obj in some_objects track by field">...</div> 

所以對於我的具體情況:

<div ng-repeat="invite in invites track by email">...</div>