1

I am trying to gain some percents in code coverage but I cant figure out how to do it. This is part of code where i am getting functions not tested.

    init(){
        this.subscription.add(someStuff.subscribe(() => this.myPrivateMethod()));
    }

    private myPrivateMethod() {
        ...
    }

Well now I am getting at least two not tested functions in code coverage. First one is this () => second one is this private myPrivateMethod() But how can I test it? The first one I have no idea and the second is private.

JGeorgeJ
  • 361
  • 7
  • 20

2 Answers2

2

Fyi you can access a private method directly with component['myPrivateMethod']().

Pascal R.
  • 2,024
  • 1
  • 21
  • 35
-1

You should always test your public interface, not private functions

Private functions could not be tested, because other files do not have access to it. You could test it with workaround, by using bracket notatation i.e component['myPrivateMethod'], but it is not recommended. You could also change it to public, then you will be able to test it.

Marek
  • 3,935
  • 10
  • 46
  • 70