jeudi 4 juillet 2019

How to mock a sub object in angular

I have an object that is returned from a service but not from an http(Observable).I want to test for only one variable of that full object.

      export interface UserState {
         benchmarkProperties: BenchmarkProperties;
         canadianClient: boolean;
         clntAnalyticsAccessible: boolean;
         usrFullNm:string;

      }

My service,

              getUserState(): UserState {
                 return this.userState;
              }

My component,

               ngOnInit(): void {
                  this.username = 
                   this.userService.getUserState().usrFullNm;
              }

My Spec,

             .mock(UserStateService, {
                getUserState: () => userState;
             });

Here from my spec,I am trying to check only for the variable 'usrFullNm' but this code itself shows red marks. I am new to testing can anyone please suggest me help.Thanks.

Aucun commentaire:

Enregistrer un commentaire