Currently, I am facing a challenge while attempting to test an AngularJS 1 controller that is written in TypeScript using Jasmine + Karma. Unfortunately, I keep encountering an error that I am struggling to resolve. The error message itself is not very descriptive:
PhantomJS 2.1.1 (Windows 8 0.0.0) Login Controller should have text" FAILED forEach@/bower_components/angular/angular.js:341:24 loadModules@/bower_components/angular/angular.js:4456:12 createInjector@/bower_components/angular/angular.js:4381:22 workFn@/bower_components/angular-mocks/angular-mocks.js:2507:60 /bower_components/angular/angular.js:4496:53 forEach@/bower_components/angular/angular.js:341:24 loadModules@/bower_components/angular/angular.js:4456:12 createInjector@/bower_components/angular/angular.js:4381:22 workFn@/bower_components/angular-mocks/angular-mocks.js:2507:60 /bower_components/angular/angular.js:4496:53 PhantomJS 2.1.1 (Windows 8 0.0.0): Executed 1 of 1 (1 FAILED) ERROR (0.019 secs / 0.015 secs)
The issue seems to revolve around my code, which appears to be quite basic and does not perform any significant actions. It appears to fail at the angular.mocks.inject
method. Interestingly enough, when I comment this out and add some simple tests, everything works as expected.
describe("Login Controller", () => {
var controller: App.Login.LoginController;
beforeEach(angular.mock.module("app.pages.auth.login"));
beforeEach(angular.mock.module($provide => {
$provide.value("$window", {});
}));
// I can get to here ok but this line below fails with the error above
// Note I have also tried putting $rootScope back in but to no avail
beforeEach(angular.mock.inject((/*$rootScope, $state, $http, $mdToast, $window, $log*/) => {
console.log("test");
}));
I have double-checked and confirmed that I have included angular-mocks.js
in my list of files, albeit towards the end of my dependency list. Additionally, it is worth mentioning that I am utilizing wiredep
for calculating my dependencies.