Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test angular filter which depend of moment.js?

I have simple filter which depends of moment.js:

app.filter('fromNow', function() {
  return function(date) {
    return moment(date).fromNow();
  }
});

Have can i write unit test of this in jasmine ?

EDIT: now i have

ReferenceError: moment is not defined

when write like that:

describe("fromNow filter", function(){
 var moment;
 beforeEach(function(){
   module('reports');
   moment = jasmine.createSpy();
  });


  it("should output string when input string",
    inject(function(fromNowFilter) {
      fromNowFilter("string");
  }));
})
like image 969
Bartek S Avatar asked Apr 28 '14 09:04

Bartek S


Video Answer


1 Answers

You need to add moment.js to the testing framework. I had the same problem and fixed adding the following line to my karma.conf.js

...files: [
   ....
    'app/bower_components/moment/moment.js',
    ....
    ],
.....
like image 59
kamayd Avatar answered Dec 08 '22 18:12

kamayd