How to Swipe a Custom Filter in Angular / Jasmine

I have my own filter that I created. for this post I created the following in my Jasmine ...

beforeEach(module("workOrderManagerApp"));
var mockSearchFilter = function(text, tails, fillTailList) {
    return null;
};
beforeEach(function() {
    module(function($provide) {
        $provide.value('searchItems', mockSearchFilter);
    });
});

      

But when I run this it still runs the weak filter. What am I missing here?

+3


source to share


1 answer


You forgot to add Filter

to the end of the filter name so that there searchItems

was searchItemsFilter

. It's not intuitive, you just have to be aware of it. Angular stores filters in the same way as services, but adds them Filter

to the end of the name you pass.

You would introduce a filter like this:



.controller('MyController', [
  'searchItemsFilter', 
  function(searchItems) {

  }
])

      

and you will mock this: $provide.value('searchItemsFilter', mockSearchFilter);

+4


source







All Articles