X Tutup
Skip to content

Can we definbe a pattern to test components with async behaviour? #11435

@vsakaria

Description

@vsakaria

I'm running RC6 and want to test a component templateUrl behaviour,

I.e Loading templates using TemplateUrl
There seems to be a fix for this as in #6601. However the code below doesn't work. Fundamentally it doesn't load the temple via templateUrl.

There is a lot of discrepancy around where to use inject, fakeAsync or aysnc.
There a solution to use a karma plugin and use a redirect for the templeUrl but I am not keen on this.

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);
        });

    }));
});



Metadata

Metadata

Assignees

No one assigned

    Labels

    area: testingIssues related to Angular testing features, such as TestBed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      X Tutup