gpt4 book ai didi

angularjs - Jasmine spyOn 没有考虑有 Angular 的垃圾

转载 作者:行者123 更新时间:2023-11-28 20:52:26 26 4
gpt4 key购买 nike

spyOn(service, someMethod).and.callThrough();

然后...

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: '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' }) ].

指令:

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

AFAICT 问题发生在调用 someControllerMethod(obj) 时 - 在该方法之外(例如,就在 obj 没有 $$hashkey 之前,但是一旦调用 someControllerMethod(),obj 就获得了错误的 key .

我假设没有办法阻止 Angular 做它做的事情,那么有什么方法可以缓解这种情况?显然我不能使用 angular.equals() 而不是 toEqual() 因为 toHaveBeenCalledWith() 方法没有公开改变比较器的方法。

最佳答案

原来这可以通过以下方式解决:

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

所以对于我的具体情况:

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

关于angularjs - Jasmine spyOn 没有考虑有 Angular 的垃圾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40689533/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com