Filter Directive Test Directive

I want to check a directive that has a filter dependency. I would like to introduce the actual filter, and not use the layout.

Here is my mockery beforeEach. How do I start typing the actual ones filter? I tried to inject as part inject function, but this does not seem to work.

beforeEach(function() {

    // filter mock
    someFilterMock = function(value) {
        return value;
    };

    // get app
    module('app');
    // get html templates
    module('templates');

    // replace filter with a mock
    module(function($provide) {
        $provide.value('someFilterFilter', someFilterMock);
    });

    // inject & compile
    inject(function($rootScope, $compile) {
        // create scope
        scope = $rootScope.$new();
        // create element using directive
        element = angular.element('<this-is-directive />');
        $compile(element)(scope);
        scope.$digest();
    });

});
+4
source share
1 answer

I do something similar in my tests:

it('uses a filter', inject(function ($filter) {
    var result = $filter('filterName')(params);
    expect(result).toBe('something');
}));

Perhaps this helps?

+1
source

All Articles