title: how to test conditional if with jasmine and angular
body: <p>i have a problem with testing jasmine, i cant test conditional if. when i run in sonarqube, just that conditional cant detect. </p>
  
  <p>this is my code: </p>
  
  <pre><code>login() {
      this.submitted = true;
      this.isLoading = true;
  
          if (this.loginForm.valid) {
            this.authenticationService
              .login(this.f.username.value, this.f.password.value)
              .pipe(finalize(() =&gt; {
                this.loginForm.markAsPristine();
                this.isLoading = false;
              }))
              .subscribe(credentials =&gt; {
                this.router.navigate(['/'], { replaceUrl: true });
              }, error =&gt; {
                this.error = error;
              });
            this.isLoading = false;
          }
        }
  </code></pre>
  
  <p>this is my testing code: </p>
  
  <pre><code>test('testing conditional if', () =&gt; {
      component.loginForm.controls['username'].setValue('admin');
      component.loginForm.controls['password'].setValue('12345678');
      expect(component.loginForm.valid).toBeTruthy();
      spyOn(authenticationService, 'login').and
        .returnValue(component.loginForm.markAsPristine());
      expect(component.login().loginForm.isLoading).toBeFalsy();
      component.login();
    });
  </code></pre>
  
  <p>help me guys to solve my problem, i search in every website but cant solve this problem. thank you for your attention and your solution. </p>