I'm currently experiencing a problem with running tests in my application. I recently transitioned to using TypeScript and am still in the learning process.
The specific error I'm encountering is:
Error: [$injector:unpr] Unknown provider: movieProvider <- movie
movie.spec.ts
import { MovieService } from './movie';
describe('service MovieService', () => {
let movieService: MovieService;
beforeEach(angular.mock.module('movieSearch'));
it('should be registered', inject((movie : MovieService) => {
expect(movie).not.toBeNull();
}));
});
movie.ts
/** @ngInject */
export class MovieService {
static $inject = ['$log', '$http', 'LoaderManager'];
public apiMovieDetail: string = 'http://www.omdbapi.com/';
/** @ngInject */
constructor(private $log: angular.ILogService, private $http: angular.IHttpService, private loader: LoaderManager) {
}
public getMovie(id: string): angular.IPromise<IMovie> {
this.loader.add();
return this.$http.get(this.apiMovieDetail + '?plot=short&r=json&i=' + id).then((response: any): any => {
this.loader.remove();
return response.data;
})
.catch((error: any): any => {
this.loader.remove();
this.$log.error('XHR Failed for getMovie.\n', error.data);
});
}
}
Successfully injecting the controller using the following code:
beforeEach(inject(($controller: angular.IControllerService) => {
mainController = $controller('MainController');
}));