How do I test a private method with Jasmine Unit tests

后端 未结 1 933
一整个雨季
一整个雨季 2021-01-15 02:54

I want to call a private method in my component

Private Method:

  private test(): void {
     return true;
  }

相关标签:
1条回答
  • 2021-01-15 03:10

    You could use

    component['test']();
    // OR in your component, add
    callMethod() {
      this.test();
    }
    

    But if I were you, I would remove the private attribute. In Javascript, there's no private attributes, only scopes.

    If you want to test your method and you can't, it means you should change your code, not adapt your test to your code. That's how you get simple and efficient code.

    (But again; that was just my two cents on your matter)

    0 讨论(0)
提交回复
热议问题