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

Testing custom provider #2274

@0x-r4bbit

Description

@0x-r4bbit

Is there anyway to get an instance of a specific provider in unit tests to test it?
I'm currently writing a custom provider and want to test it through unit tests, but there seems to be no way to that.

You can do this to configure a provider in unit tests:

...
it('spec', function () {
    module(function ($providerInstance) {
        $providerInstance.any():
    }));
});
...

Or pass module() directly as callback:

...
it('spec', module(function ($providerInstance) {
    $providerInstance.any():
})));
...

But then you're not in the right scope to use your test frameworks test methods. So this:

...
it('spec', module(function ($providerInstance) {
    $providerInstance.any():
    expect(true).toBe(false);
})));
...

Will always pass successfully.

So is there any way (maybe with angular.mocks) to get access to a provider instance in unit tests? Or shouldn't one be able to test providers, cause in code you actually deal with service instances?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions