1

I am doing testing on a simple angular code but I am getting the following error.

Error: [$injector:unpr] Unknown provider: pServiceProvider <- pService

Here are the details:

ProdModule.JS

var sapp = angular.module('productsApp', []);

ProdController.js

/// <reference path="../angular.js" />
/// <reference path="ProdModule.js" />


sapp.controller('ProductsController', function productsController($scope,      
pService) {
$scope.products = pService();
});

ProdService.js

/// <reference path="../angular.js" />
/// <reference path="ProdModule.js" />
// register the service

sapp.service('pService', function pService() {
return function getProducts() {
    return [{ name: 'Chai' }, { name: 'Syrup' }];
}
});

Test.JS

 /// <reference path="../jasmine/jasmine.js" />
/// <reference path="../dependencies/ProdModule.js" />
/// <reference path="../dependencies/ProdService.js" />
/// <reference path="../dependencies/ProdController.js" />

describe('Prod', function () {
beforeEach(module('productsApp'));
var $controller;
beforeEach(inject(function (_$controller_) {
    $controller = _$controller_;
    console.log($controller)
}));
it('should return products list on load', function () {
    var $scope = {};
    var productsController = $controller(function inlineController($scope,   
 pService) {
        $scope.products = pService();
    }, { $scope: $scope });

    expect($scope.products).toEqual([{ name: 'Chai' }, { name: 'Syrup' }]);
});
})

When I put Service code in ProdController.js then it works pefectly but when I seperate the code into each js file then the testing breaks. May I know what am I missing?

user3501278
  • 257
  • 1
  • 7
  • 21

0 Answers0