lundi 4 avril 2016

$filter is not a function while runung the test case for custome filter?

I am new to unit test and have written unit test for custom filter and I am getting the error,

$filter is not defined.

Here is my code:

For Unit Test:

describe('filter', function() {

    beforeEach(module('usp'));

    var $filter;

    beforeEach(inject(function(_$filter_){
        $filter = _$filter_;
    }));

    it('should format the date in this format MMM-DD-YYYY', function() {
      var dateFormat = $filter('dateFormat');
      expect(dateFormat('13-10-2016')).toEqual('10-13-2016');
    });
});

Custom filter:

angular.module('usp').filter('dateFormat', function () {
     return function (input) {
         return moment(input).format("MMM-DD-YYYY");
     };
 });

Please tell me where I am going wrong?

Aucun commentaire:

Enregistrer un commentaire