lundi 9 mars 2015

inject gives throws Error: [ng:areq] Argument 'fn' is not a function, got string

I am new to AngularJS and i try to develop an AngularJS app together with coffeescript in a testdriven way and cannot get inject to work. For creating the project i set it up using yeoman:



yo angular --coffee someapp


Then i created the test and the provider using



yo angular:provider testProvider


And here is the unittest for the provider i'm trying to test:



someApi = {'test': 'gets assigned'}

# load the service's module
beforeEach () ->
console.log('service module')
module 'SomeApp', (someApiProvider) ->
someApiProvider.set_salutation("Hey Guys")

beforeEach () ->
console.log('inject')
inject(
('_someApi_') ->
)
console.log('after inject')

it 'should do something', ->
expect(!!soeaidApi).toBe true


I tried different versions of the inject call like:



inject()

inject(
(_someApi_) ->
someApi = _someApi_
)

inject((_httpBackend_) -> )


and many more, but i do not see the 'after inject' in the log and the output of karma stays the same:



PhantomJS 1.9.8 (Linux) Service: someApi should do something FAILED
Error: [ng:areq] Argument 'fn' is not a function, got string
http://ift.tt/1Mle2kZ
at assertArg ($PROJ_ROOT/angular_app/bower_components/angular/angular.js:1580)
at assertArgFn ($PROJ_ROOT/angular_app/bower_components/angular/angular.js:1591)
at annotate ($PROJ_ROOT/angular_app/bower_components/angular/angular.js:3474)
at $PROJ_ROOT/angular_app/bower_components/angular-mocks/angular-mocks.js:2147
at invoke ($PROJ_ROOT/angular_app/bower_components/angular/angular.js:4163)
at $PROJ_ROOT/angular_app/bower_components/angular/angular.js:4007
at forEach ($PROJ_ROOT/angular_app/bower_components/angular/angular.js:323)
at createInjector ($PROJ_ROOT/angular_app/bower_components/angular/angular.js:4007)
at workFn ($PROJ_ROOT/angular_app/bower_components/angular-mocks/angular-mocks.js:2353)


But if i comment out the inject line i see the 'after inject' log (obviously). What am i missing, do i call inject in a wrong way, and if yes how to do it right? And what does the error log mean by the 'fn' argument?


Aucun commentaire:

Enregistrer un commentaire