我的<custom-directive>
有replace:true
和template: '<img />'
。 如何为它编写单元测试?我想我想测试它实际上是否将img替换为自定义指令。AngularJS测试指令替换设置为true
it('should be transformed to <img>', function(){
var elm = $compile('<custom-directive></custom-directive>')(scope);
scope.$digest();
var t = elm.find('img'); // wrong! it replaces the element. it won't find another one inside
//expect(elm).toBeAnImgElement ?
});
我找不到正确的匹配器。 我见过的最接近的案例是检查内容(elm.html()
或elm.text()
),但我的标签是空的。
为什么我们需要'$ rootScope $摘要();'在这里?事实上,没有它,它就无法工作,但我不明白为什么。 – thorn 2014-04-30 09:57:23
@thorn:是的,这不是必需的。 – codef0rmer 2014-04-30 17:29:27
不,是的。正如我写的,没有它就没有用。 – thorn 2014-04-30 17:46:13