Angular JS:TypeError:未定义PagePath

时间:2016-07-21 11:05:54

标签: angularjs unit-testing

执行Jasmine Angular JS Unit Test Case时出现以下错误: -

  

错误:ReferenceError:未定义PagePath

我的代码如下: -

describe('Patient Defect Management', function () {

beforeEach(module('myApp'));
var $controller;
var $httpBackend;
var myService;

beforeEach(inject(function (_$controller_) {
$controller = _$controller_;
}));

beforeEach(inject(function ($injector) {

$httpBackend = $injector.get("$httpBackend");
myService = $injector.get("angularService");
}));

afterEach(function() {
$httpBackend.verifyNoOutstandingExpectation();
$httpBackend.verifyNoOutstandingRequest();

});

it('NextAccountDetails', function () {

var $scope = {};
var controller = $controller('PatientDefectManagementCtrl', { $scope: $scope      });
var returnData = {"FacilityCode": "ABCD", "ID": "1540447"};
$httpBackend.expectGET("http://localhost:8081/Accretive.Tasks.PatientDefectManagement/Services/PatientManagement.asmx/GetDetails").respond(returnData);

var returnedPromise = myService.get('1234', 'test');
var result;
returnedPromise.then(function (response) {
    result = response.data;
});

expect(result).toEqual(returnData);
$httpBackend.flush();
 });

我的index.html中的链接

        <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.3.3/jasmine.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.3.3/jasmine.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.3.3/jasmine-html.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.3.3/boot.min.js"></script>

<!-- Angular and Angular Mock references -->
<script type="text/javascript" src="https://code.angularjs.org/1.4.0-rc.2/angular.min.js"></script>
<script type="text/javascript" src="https://code.angularjs.org/1.4.0-rc.2/angular-mocks.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-sanitize.js"></script>



<script src="/Angular/Module.js"></script>
<script src="/Angular/Service.js"></script>
<script src="/Angular/Controller.js"></script>
<script type="text/javascript" src="/AngularJSUnitTest/UnitTest.js"></script>

PagePath未定义是我现在得到的错误。这就是我现在需要解决的问题。 请帮忙

1 个答案:

答案 0 :(得分:0)

首先,你将afterEach()钩子放在它里面()测试用例。这是不正确的。将它移到beforeEach()旁边。

第一个错误通常意味着您在测试运行器(karma?)配置中出错了,并且未加载包含您服务的js文件,或者您拼错了服务名称。这样的事情。由于你没有展示这部分代码,所以很难说究竟是什么问题。