请参阅中的代码
我想知道如何添加另一个间谍来窥探$filter(‘date’)返回的方法,以便我可以验证
expect(something,something).toHaveBeenCalledWith('1234','dd-MMM-yyyy');
你应该能够模拟传递给控制器的过滤器,并从这个模拟中返回一个间谍.然后,您可以测试间谍是否正常调用.
例:
describe('MyCtrl',function () { var filter,innerFilterSpy,http,scope; beforeEach(inject(function ($rootScope,$controller,$http) { http = $http; innerFilterSpy = jasmine.createSpy(); filter = jasmine.createSpy().and.returnValue(innerFilterSpy); scope = $rootScope.$new(); controller = $controller('MyCtrl',{ '$scope': scope,'$http': http,'$filter': filter }); })); it('call $filter("date") and test()',function () { expect(scope.date).toBe('01-Jan-1970'); expect(http.get).toHaveBeenCalled(); expect(filter).toHaveBeenCalledWith('date'); expect(innerFilterSpy).toHaveBeenCalledWith('1234','dd-MMM-yyyy'); }); });
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。