My method is simply like this in angular 5:

  public login(data): Promise<any> {
    const vm : any = this;

    return new Promise((resolve, reject) => {
      let url ="www.example.com"
      vm.http.post(url, data).toPromise().then(
        resp => {
          resolve(resp);
        }).catch(err=>{
          reject(err)
        })
    });
  }

The URL is usually dependent on the body but let's just assme it is 
example.com for now. I want to write a unit test that ensures an http call 
was made to a given url but for now, it just says "found none" and fails:


it("should login user", fakeAsync(() => {

    let response = {
      resultCount: 1    
    };

    service
    .login(
     {'name':'name'}
    )
    .then(result => {
      expect(result).toEqual(response);
    });

    flushMicrotasks();


    // Expect a call to this URL
      const req = httpTestingController.expectOne(
      "www.example.com"
    );
    expect(req.request.method).toEqual("POST");
    req.flush(response);
    tick();

  }));

How do i unit test the method. It is driving me crazy.

-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to angular+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/angular/78bb7d92-9d9f-4e0e-ba88-5d0623d5246a%40googlegroups.com.

Reply via email to