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()-它没有帮助