AngularJS - $filter not in global scope -
i trying write unit test filter wrote in angular (1.0.7). filter working on actual page, know getting registered correctly. want write unit test it.
var application = angular.module('customer', []); application.filter('date', function () { return function (date) { return moment(date).format('mm/dd/yyyy'); }; });
at top of test page, include angular.js file.
<script type="text/javascript" src="../angular.js"></script>
supposedly, there $filter
function retrieving registered filters. debugger freaks out , says it's not there. can see actual angular
variable, know angular being included correctly.
i wondering if missing .js file or if $filter
in different scope or newer version of angular.
you can use $filter('date')
date
filter injecting $filter
module before test stub. created working demo , please take @ required js files.
describe('date', function () { var datafilter; beforeeach(angular.mock.module('customer')); beforeeach(function () { angular.mock.inject(function ($filter) { datafilter = $filter('date'); }) }); describe('date result', function () { it('should return filtered date', function () { var date = new date(2013, 7, 15); expect(datafilter(date)).tobe('08/15/2013'); }); }); });
Comments
Post a Comment