jeudi 30 avril 2020

Sonar reports 0% coverage for a public method invoked from a private method

This an Angular 9 project where in an injectable angular service is invoking it's private method from a constructor.

export class Service {
    private serviceVariable: string;

    constructor(private someOtherService: SomeOtherService) {
        this.serviceVariable = 'Hello Angular Service!';
        this.someOtherService.getObservable().subscribe(value => {
            this.handleThisNow(value);
        });
    }



    private handleThisNow(value) {
        if (value > 0) {
            this.anotherPrivateMethod(value);
        } else {
            this.aPublicMethod(value);// sonar shows 0% coverage for this line and build fails for new code
        }
    }
    }

What is wrong in this class? Is it wrong to invoke a non-private method from a private method? Or is it wrong to invoke a private method from a constuctor?

Aucun commentaire:

Enregistrer un commentaire