how to unit test custom $filter by mocking in ES6 class for angular controller
<p>I have a ES Class written for a angular controller and i am trying to write jasmine tests using angular-mock.</p>

<p>In the constructor I initialize $filter to this.i18n = $filter('i18n), which is basically a localization filter that takes a key, value  and returns teh localized value for the key.</p>

<p>My problem is that since teh constructor of the class has the $filter  and is later on used in the class methods. My unit tests fail. How could i test using $filter such that my tests dont fail. I am looking to mock the custom filter </p>

<p>Here is the exception that i get</p>

<pre><code>  TypeError: this.i18n is not a function
    at UsersCtrl.$onInit (test-context.js:35081:41)
    at Object.&lt;anonymous&gt; (test-context.js:35031:31)
</code></pre>

<p>Here is the ES6 Class </p>

<pre><code>class UsersCtrl {
    constructor($filter) {
        this.i18n = $filter('i18n');
        this.users = [];
    }
   //Life cycle Hooks: Initialization
   $onInit() {
        this.users = [
            {name: this.i18n('USERS')}
        ];
      }
}
UsersCtrl.$inject = ['$filter'];

angular.module('app', []).controller('UsersCtrl',UsersCtrl);

export default UsersCtrl;
</code></pre>

<p>Here is the Unit test that i have</p>

<pre><code>Import UsersCtrl from './users-controller.js';

     describe("given a new User Page", () =&gt; {
        var UserController;
        beforeEach(() =&gt; {
          angular.mock.module('app');
        });

    describe("when initialising  has completed", () =&gt; {
      beforeEach(() =&gt; {
         inject(($rootScope, $controller, $filter) =&gt; {
             const scope = $rootScope.$new();
             const filter = $filter
             UserController = $controller("UsersCtrl", { $scope: scope, $filter: filter});
          });
       });
    it("then users array for tab content should be empty initially",() =&gt; {
        const expectedActive = [];       
        expect(UserController.users).toEqual(expectedActive);
     });
    });
   });
</code></pre>

<p>The issue is it runs the test but fails as its unable to initialize with       this.i18n = $filter('i18n).How should i initialize the test to pass $filter into the tests? Could i mock the filter as i dont really want to test the filter here </p>