我开始学习角度2并希望通过单元测试来解决问题。所以我希望我的所有指令/组件都能用测试来编写。
在angularJS(第一版)中测试指令您使用class ServerSerializer(serializers.ModelSerializer):
class Meta:
model = Server
fields = ( 'node')
。以下来自doc:
$compile
如何在角度2中编译html文本来编写测试?
我想测试最简单的直接:
it('Replaces the element with the appropriate content', function() {
var element = $compile("<a-great-eye></a-great-eye>")($rootScope);
$rootScope.$digest();
expect(element.html()).toContain("lidless, wreathed in flame, 2 times");
});
答案 0 :(得分:1)
使用TestComponentBuilder
it('should reflect added elements',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideTemplate(TestComponent, TEMPLATE)
.createAsync(TestComponent)
.then((fixture) => {
fixture.detectChanges();
(<number[]>fixture.debugElement.componentInstance.items).push(3);
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('1;2;3;');
async.done();
});
}));
release-1.0