Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No http response in angular HttpClient context using mocha #3

Open
nowrap opened this issue Feb 19, 2020 · 0 comments
Open

No http response in angular HttpClient context using mocha #3

nowrap opened this issue Feb 19, 2020 · 0 comments

Comments

@nowrap
Copy link

nowrap commented Feb 19, 2020

Hello,
i am trying to build a mocha test for parts of an ionic 3 (angular 5) app.

I created an angular HttpClient with your XMLHttpRequest:

import { Injector } from '@angular/core';
import { HttpClient, HttpHandler, HttpXhrBackend, XhrFactory } from '@angular/common/http';
import { XMLHttpRequest } from 'xmlhttprequest-ts';

export class BrowserXhr implements XhrFactory {
    build(): any { return <any>(new XMLHttpRequest()); }
}
        const injector: Injector = Injector.create({
            providers: [
                { provide: HttpClient, deps: [HttpHandler] },
                { provide: HttpHandler, useValue: new HttpXhrBackend(new BrowserXhr()) },
            ],
        });
        const httpClient: HttpClient = injector.get(HttpClient);

Retriving local json files with a file:// url works.
Doing get or post requests are submitted and processed on the server side. But i am not getting the body. The result header is within. Instead i receive an object starting with "result: IncomingMessage {".

I tried using the webstorm debugger but couldn't get any clues. It uses first the node_modules/xmlhttprequest-ts/bundles/xmlhttprequest-ts.umd.js but switches to XMLHttpRequest.ts at line 442 "if (this.settings.async) {" ignoring my further breakpoints.

I guess it is somehow related to the responseHandler.

Regards
nowrap

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant