Angular-mocks $injector doesn't return service, no $get method

182 views Asked by At

I am attempting to do my best at bdd with Karma and Mocha. I have created this shell of a service to try to get things going (generated from TypeScript) enter image description here

I have created the following test

enter image description here

I put a break point on the line where the injector gets the service and when it breaks the debugger tells me that scheduleService exists to the injector

enter image description here

But when I executed the $injector.get method it fails with this error

enter image description here

What am I doing wrong this time?

2

There are 2 answers

0
pthalacker On BEST ANSWER

The problem was with what I was passing to the factory. I changed the factory method parameters to

enter image description here

and now my test is working.

2
Vadim On

You are using a factory. A factory needs to return an object. Your factory is returning a function, hence the error you are seeing. You are likely needing to use a service instead. The slight difference between a factory and a service is that a factory returns an object provided, while the service returns an object invoked with a new to create the instance.

angular.module('tsid.scada').service('scheduleService', tsid.scada.scheduleService);