如何在角度2中编译html?

时间:2016-01-15 09:19:27

标签: angularjs angular

我开始学习角度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");
  });

1 个答案:

答案 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