Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 角度';s element.isolateScope()返回未定义的_Angularjs_Unit Testing_Chai - Fatal编程技术网

Angularjs 角度';s element.isolateScope()返回未定义的

Angularjs 角度';s element.isolateScope()返回未定义的,angularjs,unit-testing,chai,Angularjs,Unit Testing,Chai,我正在为编写一个测试,我相信我做的是正确的,但是当我尝试访问isolateScope时,我没有定义 指令: describe('directive: deposit-note', function() { var expect = chai.expect; var element, scope, $rootScope, $compile, $httpBackend; beforeEach(module('directives.dep

我正在为编写一个测试,我相信我做的是正确的,但是当我尝试访问isolateScope时,我没有定义

指令:

describe('directive: deposit-note', function() {
  var expect = chai.expect;

  var element,
      scope,
      $rootScope,
      $compile,
      $httpBackend;

  beforeEach(module('directives.depositnote'));

  beforeEach(inject(function (_$compile_, _$rootScope_) {
      $compile = _$compile_;
      $rootScope = _$rootScope_;
  }));

  beforeEach(inject(function($injector) {
    $httpBackend = $injector.get('$httpBackend');
  }));

  describe('with a filled-out transaction object', function() {

    beforeEach(inject(function($injector) {
      $httpBackend.whenGET('/templates/depositnote.tpl.html').respond(200, '');
      scope = $rootScope.$new();

      element = '<deposit-note checknumber="transaction.checkNumber" checktype="transaction.checkType.value" depositnote="transaction.depositNote" />';

      scope.transaction = {
        "checkNumber": "1234",
        "checkType": "CASHIERS CHK",
        "depositNote": "In Person"
      };

      element = $compile(element)(scope);
      scope.$digest();
    }));

    it("should calculate the correct remaining characters", function() {
      var isolated = element.isolateScope();
      expect(isolated.totalRemaining).toBe(17);
    });  
  });
});
description('指令:存款单',函数()){
var expect=chai.expect;
var元素,
范围
$rootScope,
$compile,
$httpBackend;
之前(模块('directions.depositnote'));
beforeach(注入函数($compile,$rootScope){
$compile=\$compile;
$rootScope=\u$rootScope;
}));
每次之前(注入(函数($injector){
$httpBackend=$injector.get(“$httpBackend”);
}));
description('带有填写的事务对象',function()){
每次之前(注入(函数($injector){
$httpBackend.whenGET('/templates/depositnote.tpl.html')。响应(200,');
scope=$rootScope.$new();
元素=“”;
scope.transaction={
“支票号码”:“1234”,
“支票类型”:“出纳CHK”,
“存单”:“亲自”
};
元素=$compile(元素)(范围);
范围。$digest();
}));
它(“应计算正确的剩余字符”,函数(){
var isolated=element.isolateScope();
期望值(孤立的,剩余的)toBe(17);
});  
});
});
当我逐步完成这一步时,我看到元素被编译,chrome的devtools显示
element.isolateScope()
确实是元素上的一个方法,但它返回未定义的


我缺少什么?

我的karma.config文件的基本url不正确,无法访问模板缓存中的模板(我使用html2js)。因此,基本上模板不可用,因此指令从未编译,这就是为什么从未创建隔离作用域。

标题中的函数名拼写错误:isolatedScope()应该是isolatedScope()。只是对像我这样的复制粘贴者的一个警告:-)>(刚刚修复)