Bạn có thể giả lập bộ lọc được chuyển vào bộ điều khiển và trả lại một gián điệp từ mô hình này. Sau đó bạn có thể kiểm tra rằng điệp viên được gọi là bình thường.
Ví dụ:
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');
});
});
này đã giúp nhưng tôi muốn chỉ ra nó gây hiểu lầm để bơm $ lọc kể từ khi bạn không sử dụng nó. – Alex
Cảm ơn, tôi đã xóa nội dung đó ngay bây giờ. – fiznool