spyOn(service, someMethod).and.callThrough();
then...
var an_object = some_objects[0];
useADirectiveThatRepeatsOver(some_objects);
expect(service.someMethod).toHaveBeenCalledWith(an_object);
fails with
Expected spy someMethod to have been called with [ Object({
sent_date: '2016-11-18T12:06:29.712318Z',
email: 'pigeon@wacky.races', url: '/api/v1/invites/1/' }) ]
but actual calls were [ Object({
sent_date: '2016-11-18T12:06:29.712318Z',
email: 'pigeon@wacky.races', url: '/api/v1/invites/1/',
$$hashKey: 'object:110' }) ].
The directive:
<div ng-repeat="obj in some_objects">
<span ng-click="someControllerMethod(obj)"></span>
</div>
The issue, AFAICT, occurs when someControllerMethod(obj) is called - outside of that method (e.g. right before the obj does not have $$hashkey, but as soon as someControllerMethod() is called, obj has gained the errant key.
I'm assuming there's no way to prevent angular doing what it do, so what are some ways of mitigating this? Clearly I can't use angular.equals() instead of toEqual() since the toHaveBeenCalledWith() method doesn't expose a way to change the comparator.
Aucun commentaire:
Enregistrer un commentaire