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

ngMock fails at $componentController after update from 1.4.8 to 1.5.0 #13969

Closed
ctaepper opened this issue Feb 7, 2016 · 7 comments
Closed

Comments

@ctaepper
Copy link

ctaepper commented Feb 7, 2016

i have no idea whats up?

Error: [$injector:modulerr] Failed to instantiate module ngMock due to:
Error: [$injector:pget] Provider '$componentController' must define $get factory method.

FYI: tests are also working in 1.4.9

after some digging:
https://github.com/angular/angular.js/blob/v1.5.0/src/ngMock/angular-mocks.js#L2186
shouldn't this read this.$get = ....? after fixing that in the dist file, the tests are working

also, to clarify, I am running tests on module, which only consists of services and factories

@petebacondarwin petebacondarwin self-assigned this Feb 8, 2016
@petebacondarwin petebacondarwin added this to the 1.5.1 milestone Feb 8, 2016
@petebacondarwin
Copy link
Contributor

Yes, I think you are right. I'll fix it.

@gkalpak
Copy link
Member

gkalpak commented Feb 8, 2016

Interesting that our tests didn't catch this 😕

@petebacondarwin
Copy link
Contributor

It is because our unit tests for ngMock do not rely on instantiation via the injector.

@petebacondarwin
Copy link
Contributor

I take that back. We do use the injector.... not sure why this doesn't fail in our unit tests then...

@petebacondarwin
Copy link
Contributor

This is weird. We do indeed instantiate the $componentController service via the $injector in our ngMock tests and the full set of tests pass whether the provider is setup using the this.$get = ... style or the return { $get: ... } style.

So in the injector we have these lines:

  function provider(name, provider_) {
    assertNotHasOwnProperty(name, 'service');
    if (isFunction(provider_) || isArray(provider_)) {
      provider_ = providerInjector.instantiate(provider_);
    }
    if (!provider_.$get) {
      throw $injectorMinErr('pget', "Provider '{0}' must define $get factory method.", name);
    }
    return providerCache[name + providerSuffix] = provider_;
  }

So you can see that we are "instantiating the function that is passed. We ought to be able to have the constructor return an object and that be used instead.

I wonder if this is some browser/jsdom specific thing where instantiating in that environment does not work with a constructor returning an object?

@ctaepper can you confirm how you are running the tests?

@petebacondarwin
Copy link
Contributor

But I guess we can change it for consistency anyway

petebacondarwin added a commit to petebacondarwin/angular.js that referenced this issue Feb 8, 2016
petebacondarwin added a commit to petebacondarwin/angular.js that referenced this issue Feb 9, 2016
petebacondarwin added a commit that referenced this issue Feb 9, 2016
@ctaepper
Copy link
Author

@petebacondarwin sorry for late response! yes i do my tests exactly like that. i pinned it down to PhantomJS. I was using 1.9.x, which apparently can't handle it (did before with ng 1.4.8). I switched to 2.1.x and everything works fine.

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

3 participants