jasmine spyOn angularjs内部方法,例如$filter(‘date’)
发布时间:2020-12-17 07:29:22 所属栏目:安全 来源:网络整理
导读:请参阅中的代码 http://jsfiddle.net/2Ny8x/69/ 我想知道如何添加另一个间谍来窥探$filter(‘date’)返回的方法,以便我可以验证 expect(something,something).toHaveBeenCalledWith('1234','dd-MMM-yyyy'); 你应该能够模拟传递给控制器??的过滤器,并从这个模
请参阅中的代码
http://jsfiddle.net/2Ny8x/69/ 我想知道如何添加另一个间谍来窥探$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'); }); }); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |