3

I have a custom filter I created. per 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 non-mock filter. What am I missing here?

Community
  • 1
  • 1
Jackie
  • 21,969
  • 32
  • 147
  • 289

1 Answers1

5

You forgot to add Filter to the end of your filter name so that searchItems would be searchItemsFilter. It isn't intuitive, you just have to know about this. Angular stores filters just like services, but adds Filter to the end of the name you pass in.

You would inject a filter like this:

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

  }
])

and so you would mock it with: $provide.value('searchItemsFilter', mockSearchFilter);

m59
  • 43,214
  • 14
  • 119
  • 136