Reputation: 588
filterTest.js
'use strict';
describe('test the reverse string filter',function(){
var customFilter;
beforeEach(module('directiveApp'));
beforeEach(inject(function($filter){
customFilter = $filter('reversing');
}));
it('passing a filter test',function(){
expect(customFilter('HELLO')).toBe('OLLEH');
});
});
filterModule.js
angular.module('directiveApp').filter('reversing',function(text){
return text.split("").reverse().join("");
});
filterTest.js is my test file in which i am trying to test the filter that i have created in 'directiveApp' module which reverses the string. When i run karma start
it was giving an error:
TypeError: undefined is not a function (evaluating 'customFilter('HELLO')') in /var/www/html/Directive/tests/testFilter.js (line 10) /var/www/html/Directive/tests/testFilter.js:10:25
I am unable figure it out, what wrong with it. Any help is appreciated. Thanks,
Upvotes: 0
Views: 830
Reputation: 691645
Your filter is not defined correctly. It should be:
angular.module('directiveApp').filter('reversing', function() {
return function(text) {
return text.split("").reverse().join("");
};
});
Upvotes: 1