Kenneth Lynne Kenneth Lynne - 1 month ago 4x
AngularJS Question

How can i test a AngularJS provider?

I need to test my own angular provider, and I need to test it in both config and run phase to check that config methods work and that the instantiated provider is indeed configured with the correct parameters.

When I ask dependancy injection for the provider, it can't find the APIResourceFactoryProvider, only the APIResourceFactory, and I haven't found any examples of this on the repositories I've looked trough so far.


It's actually a lot simpler than it would at first seem to test a provider in AngularJS:

describe('Testing a provider', function() {
  var provider;

  beforeEach(module('plunker', function( myServiceProvider ) {
      provider = myServiceProvider;

  it('should return true on method call', inject(function () {
    expect( provider.method() ).toBeTruthy();


The proof is in the Plunker: