Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/403.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.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
Javascript Angularjs指令测试-编译似乎没有';行不通_Javascript_Angularjs_Unit Testing_Coffeescript_Jasmine - Fatal编程技术网

Javascript Angularjs指令测试-编译似乎没有';行不通

Javascript Angularjs指令测试-编译似乎没有';行不通,javascript,angularjs,unit-testing,coffeescript,jasmine,Javascript,Angularjs,Unit Testing,Coffeescript,Jasmine,我试图测试我的角度指令,但没有成功 describe 'mylist directive', () -> beforeEach module 'myModule' beforeEach module 'my-tpl' beforeEach inject (_$httpBackend_, _$templateCache_) -> @$httpBackend = _$httpBackend_ @$templateCache =

我试图测试我的角度指令,但没有成功

describe 'mylist directive', () ->

    beforeEach module 'myModule'

    beforeEach module 'my-tpl'

    beforeEach inject (_$httpBackend_, _$templateCache_) ->
        @$httpBackend = _$httpBackend_
        @$templateCache = _$templateCache_

    it 'Replaces the element with the appropriate content', () ->
        inject ($compile, $rootScope) ->
            rootScope = $rootScope.$new()
            @$httpBackend.when('GET', 'list.html').respond @$templateCache.get 'list.html'
            element = $compile('<mylist ng-model="items" title="Test"></mylist>')(rootScope)
            rootScope.$digest()
            console.log element
            expect(element.html()).toContain "sometext"
描述“mylist指令”,()->
在每个模块“myModule”之前
在每个模块“我的tpl”之前
每次注入之前($httpBackend_uu,$templateCache)->
@$httpBackend=\$httpBackend_
@$templateCache=\u$templateCache_
它“用适当的内容替换元素”,()->
注入($compile,$rootScope)->
rootScope=$rootScope.$new()
@$httpBackend.when('GET','list.html')。respond@$templateCache.GET'list.html'
元素=$compile(“”)(根范围)
rootScope.$digest()
console.log元素
expect(element.html()).toContain“sometext”
出于某种原因,console.log()打印原始内容而不是编译内容:

Object{0: <mylist ng-model="items" title="Test" class="ng-scope"></mylist>, length: 1}
对象{0:,长度:1}
(@$templateCache.get'list.html'返回正确的模板-我已检查)


任何建议都会很有帮助……

您确定有
mylist
指令吗?尝试
rootScope.$apply()
而不是
rootScope.$digest()
。感谢您的回复。mylist是在myModule中定义的。我正在尝试rootScope。$apply()-它没有帮助