Yatrix Yatrix - 4 years ago 113
AngularJS Question

Why isn't $injector finding $state in my unit test?

The following is my module and unit test set-up. When I try to set $

throws the always fun Unknown provider: $stateProvider <- $state error and I don't understand why.

angular.module("my-module", [
//Third Party

describe("something descriptive and helpful", (): void => {
// a bunch of other service variables....
var $state: any;

// I've tried with and without this line
beforeEach(() => angular.module("ui.router"));

beforeEach(() => {


inject(($injector: ng.auto.IInjectorService): void => {
// a bunch of other service variable assignments
$state = $injector.get("$state");

Answer Source

You need to call


to load the module.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download