Angular Unit testing a method that does not have any return statement

297 views Asked by At

My method :

flyout() {
    document.getElementById("transition1").style.cssText="transform:translateX(-120%)";
    document.getElementById("transition2").style.cssText="transform:translateY(-120%)";
}

spec.ts :

it('Tesing Void function', function() {
    const fixture = TestBed.createComponent(AppComponent);
    fixture.detectChanges();
    const component = fixture.debugElement.componentInstance;
    component.flyOut();
    // How should I write expect statement
});

Can anyone help me how to write expect statment....

Thanks.!!!

1

There are 1 answers

2
Marek W On

You can query your element in your expect and check whether the style has been applied or not.

fixture.detectChanges();
expect(fixture.debugElement.query(By.css('#transition1')).style.transform).toEqual('translateX(-120%)');