Testing Filters

Testing your custom filters in AngularJS can be very simple if you keep them straightforward. To illustrate this, consider the following custom filter and test:

myModule.filter('nospace', function() {  return function(text){    return text.replace(' ', '');  }});var nospace = $filter('nospace');expect(nospace('my words')).toEqual('mywords');

Get Learning AngularJS now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.