将属性添加到应用程序根目录以进行茉莉花测试

时间:2018-08-21 12:59:22

标签: javascript angular unit-testing jasmine

我们有一个Angular应用程序(6.1.0),该应用程序已被另一个网站使用。网站与网站的交流方式是通过向应用程序根目录添加属性,例如:

<app-root isEnabled="true" backendApi="http://fake.url">
</app-root>

app.component.ts将其加载到构造中。

我当前正在编写一个茉莉花测试,以测试app.component.ts是在读取这些值还是在创建组件时未设置期望值的情况下引发错误。

在创建组件之前,是否可以在app-root元素上设置属性:

类似以下内容:

it('should warn if attributes are missing from app-root', async(() => {
    globalTestElemet.find('app-root').setAttribute('isEnabled','true'); <- Is this possible?

    //Create the component and continue with test...
}));

我知道您可以通过以下方式获取html元素:

const fixture = TestBed.createComponent(AppComponent);
const compiled = fixture.debugElement.nativeElement;

但这需要已创建组件。

0 个答案:

没有答案