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()方法沒有公開方法來改變比較器。