troyanskiy / ngx-resource-core

RESTful Core Library
40 stars 10 forks source link

Resource does not make http call in unit test #47

Closed agenaille closed 5 years ago

agenaille commented 5 years ago

Issue description

When invoking a resource's http call in an Angular 6 unit test, the request doesn't fire, and cannot be captured with the HttpTestingController.expectOne function.

Steps to reproduce the issue

Here is my code:

@Injectable()
@ResourceParams({
  pathPrefix: '/api/{!version}'
})
export class IntegrationResourceService extends Resource {

  @ResourceAction({
    method: ResourceRequestMethod.Get,
    path: '/service-one/{!id}'
  })
  get: IResourceMethod<{ id: string }, any>;

  @ResourceAction({
    method: ResourceRequestMethod.Post,
    path: '/service-two'
  })
  post: IResourceMethodStrict<any, any, any, any>;

  constructor(handler: ResourceHandler) {
    super(handler);
  }
}

Unit Test:

   it('should fire request', () => {
    service.post('123', data);
    httpTestingController.expectOne('/api/v1/service-two').flush(null, { status: 200, statusText: 'Ok' });
    httpTestingController.verify();
  });

What's the expected result?

What's the actual result?

Does this module work with the HttpClientTestingModule and HttpTestingController? Is there any way you can provide a working unit test example?

troyanskiy commented 5 years ago

Hello @agenaille I will make some tests and add them to the README.md soon

Thank you for the issue.

agenaille commented 5 years ago

@troyanskiy Thanks for your help. I actually think the request is being fired, just not being caught by the HttpClientTestingModule/Controller.

agenaille commented 5 years ago

bumping this

troyanskiy commented 5 years ago

Hello @all I have made some unit test example at the end of the README.MD file.