I have some troubles writing tests for my services in my angularJS project. I am using Karma and Jasmine for my unit tests. To begin, I chose a service with no dependencies, but I never had passed the tests.
Here's my service ( written with coffeeScript )
angular.module('app').factory 'rankFactory', [ ->
rankFactory = {}
ranks = [
{
id: 0
label: 'RANK0'
}
{
id: 1
label: 'RANK1'
}
]
rankFactory.getRanks = ->
ranks
rankFactory.getRanks = (id) ->
ranks[id]
rankFactory
]
The service works fine. Thus, the test doesn't. Here's my test :
describe('rank Factory unit tests', function(){
describe ('when I call myService rankFactory.getRanks ()', function() {
beforeEach(module('app'));
it('returns ranks', inject(function(rankFactory){
expect(rankFactory.getRanks()).not.to.equal(null);
}))
}
)
});
I have been trying for multiple hours, and read a lot of issues and documentation but still can not find out why it doesn't work. Can you help me please?
Aucun commentaire:
Enregistrer un commentaire