Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

ngMock - 1.5.0-beta.2 - Error: [ng:areq] Argument 'fn' is not a function, got string #13397

Closed
albertosantini opened this issue Nov 27, 2015 · 9 comments

Comments

@albertosantini
Copy link

Upgrading to 1.5.0-beta.2 from 1.4.8 I get the following exception:

Error: [ng:areq] Argument 'fn' is not a function, got string
http://errors.angularjs.org/1.5.0-beta.2/ng/areq?p0=fn&p1=not%20a%20function%2C%20got%20string
    at https://code.angularjs.org/1.5.0-beta.2/angular.js:68:12
    at assertArg (https://code.angularjs.org/1.5.0-beta.2/angular.js:1810:11)
    at assertArgFn (https://code.angularjs.org/1.5.0-beta.2/angular.js:1820:3)
    at Function.annotate (https://code.angularjs.org/1.5.0-beta.2/angular.js:3930:5)
    at Function.angular.injector.$$annotate (https://code.angularjs.org/1.5.0-beta.2/angular-mocks.js:2461:36)
    at Object.invoke (https://code.angularjs.org/1.5.0-beta.2/angular.js:4626:36)
    at https://code.angularjs.org/1.5.0-beta.2/angular-mocks.js:2544:43
    at Object.forEach (https://code.angularjs.org/1.5.0-beta.2/angular.js:340:20)
    at workFn (https://code.angularjs.org/1.5.0-beta.2/angular-mocks.js:2533:17)
    at window.module.angular.mock.module (https://code.angularjs.org/1.5.0-beta.2/angular-mocks.js:2526:30)

It seems related to the module definition: beforeEach(module("app"));

I reproduced the issue in this plunker (with 1.4.8 is ok):
http://plnkr.co/edit/Y1zGI2rlbCVVDLFRT1mO?p=preview

Weirdly removing a spec, there are two equal specs loaded in index.html, the test is ok.

Project reference: https://github.com/albertosantini/argo
You can change karma.conf accordingly setting 1.5.0-beta.2.

@waeljammal
Copy link

Having same issue here, first test works second test throws the above error.

@Narretz
Copy link
Contributor

Narretz commented Nov 29, 2015

Hm, strange, The only public changes to ngMock are these two fd83d37 and 51a27c0

@waeljammal Do you also use mocha?

@waeljammal
Copy link

Yes i use mocha, sinon, chai

@albertosantini
Copy link
Author

Indeed 51a27c0 modifies workFn, changing the implementation of angular.mock.module and handling modules differently.

The offending line in user code is module('app'); (in the above plunker) and it is related to window.module.angular.mock.module in https://code.angularjs.org/1.5.0-beta.2/angular-mocks.js:2526:30), as stated in the stack trace of the exception.

@petebacondarwin
Copy link
Contributor

It seems that mocha is reusing the currentSpec context for both specs, whereas Jasmine creates a new context. We should be clearing out the special properties that we added to the spec (see

currentSpec.$injector = null;
) but we forgot to clear out $providerInjector.

JASMINE

http://plnkr.co/edit/apJQMAxys2DWizObuYYK?p=preview

describe SimpleService called
describe DoSomething called
describe SimpleService2 called
describe DoSomething2 called
window beforeEach 0

window beforeEach2 1
beforeEach called 1
it should log the message called 1
something done!
window afterEach2 1
window afterEach 1

window beforeEach 2
window beforeEach2 2
beforeEach2 called 2
it should log the message called2 2
something done!
window afterEach2 2
window afterEach 2

MOCHA

http://plnkr.co/edit/OccCN20WNBZCWMRCKmEV?p=preview

describe SimpleService called
describe DoSomething called
describe SimpleService2 called
describe DoSomething2 called

window beforeEach 0

window beforeEach2 1
beforeEach called 1
it should log the message called 1
something done!
window afterEach 1
window afterEach 1

window beforeEach 1
window beforeEach2 1
beforeEach2 called 1
// Crash
window afterEach 1
window afterEach 1

petebacondarwin added a commit to petebacondarwin/angular.js that referenced this issue Nov 30, 2015
@petebacondarwin
Copy link
Contributor

I will make a PR - sadly it is rather hard to unit test this!

@petebacondarwin
Copy link
Contributor

My commit (9298344) appears to fix the problem.
See http://plnkr.co/edit/3VPxHus4ky59OPc0ro46?p=preview

@petebacondarwin
Copy link
Contributor

Here you go: #13416

@raoulus
Copy link

raoulus commented Dec 1, 2015

I also run into this issue.. Thanks for reporting.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants