TemplateUrl未在Karma的Angular 2单元测试中加载

时间:2016-09-08 10:07:22

标签: angular webpack karma-runner

我正在运行RC6并希望测试组件templateUrl行为,

即使用TemplateUrl加载模板 似乎有一个解决方法,如https://github.com/angular/angular/pull/6601。但是,下面的代码不起作用。从根本上说,它不会通过templateUrl加载太阳穴。

在使用inject,fakeAsync或aysnc的地方存在很多差异。 有一个解决方案使用karma插件并使用templeUrl的重定向,但我不喜欢这个。

import { Component, Input, OnInit} from "@angular/core";


import { TooltipService } from "./tooltip.service";

@Component({
    selector: "tooltip",
    templateUrl: "./tooltip.component.html",
    providers: [TooltipService]
})

export class TooltipComponent {}

const INITIAL_QUESTIONS: any = { step: {
    questions: [
        {
            key: "q1",
            questionId: "question1",
            displayText: "Question 1's value",
            answerChoices: [
                { answerId: "abc$def", displayText: "Answer 1", selected: true },
                { answerId: "123$def", displayText: "Answer 2", selected: false }
            ]
        }
    ]
}};
fdescribe("ToolTipComponent", () => {
    beforeEach(() => {
        TestBed.configureTestingModule({
            declarations: [
                TooltipComponent
            ],
            providers: [
               { provide: TooltipService, useClass: MockToolTipService }
            ]
        });

        this.fixture = TestBed.createComponent(TooltipComponent);
    });

    it("should render the template", async(() => {
        this.fixture.whenStable().then(() => {
            let element = this.fixture.nativeElement;
            this.fixture.detectChanges();

            expect(element.querySelectorAll("div").length).toBe(1);
        });

    }));
});

0 个答案:

没有答案
相关问题