Error: Cannot make XHRs from within a fake async test.

See original GitHub issue

Steps to reproduce and a minimal demo of the problem

What steps should we try in your demo to see the problem?

export function setupComponentFakeAsync(type:any, continuation:Function) {
    return fakeAsync(inject([TestComponentBuilder], (tcb:TestComponentBuilder) => {
        let fixture:ComponentFixture = null;
        tcb.createAsync(type).then((f:ComponentFixture) => fixture = f);
        tick(50);
        fixture.detectChanges();
        continuation(fixture);
    }));
}


it('shows an empty origin station text field in the default component state',
    setupComponentFakeAsync(SearchComponent, (fixture:ComponentFixture) => {
        let input:any = fixture.nativeElement.querySelector('#fromStation');

        expect(input.value).toBe('');
    })
);



**Current behavior**
Exception:

> Error: Cannot make XHRs from within a fake async test. in d:/Users/l026291/Development/ts-automat-fe/node_modules/zone.js/dist/fake-async-test.js (line 248)
    onScheduleTask@d:/Users/l026291/Development/ts-automat-fe/node_modules/zone.js/dist/fake-async-test.js:248:96
    scheduleTask@d:/Users/l026291/Development/ts-automat-fe/node_modules/angular2/bundles/angular2-polyfills.js:359:64
    scheduleMacroTask@d:/Users/l026291/Development/ts-automat-fe/node_modules/angular2/bundles/angular2-polyfills.js:299:52
    d:/Users/l026291/Development/ts-automat-fe/node_modules/angular2/bundles/angular2-polyfills.js:148:39
    send

**Expected/desired behavior**
The test is working just as with beta 15.

**Other information**

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:9
  • Comments:21 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
yjaaidicommented, Jun 17, 2016

+1

0reactions
angular-automatic-lock-bot[bot]commented, Sep 13, 2019

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

4 - Stack Overflow
Angular 6 Error : Cannot make XHRs from within a fake async test. Request URL: https://mlj0xk2yy.com/latest/static/videos.
Read more >
my testing.spec.ts doesn't work. error: cannot make xhrs from ...
Error: Cannot make XHRs from within a fake async test. ... Error clearly says that you cannot make XHR requests using fakeAsync ....
Read more >
Angular Unit Testing 101 - ITNEXT
It's about Angular 2+ Unit Test. ... I usually use this fake HttpClient call to avoid “Cannot make XHRs from within a fake...
Read more >
Testing Asynchronous Code with FakeAsync in Angular
In this tutorial, we take a look at how to use fakeAsync, flushMicrotasks, and tick to test asynchronous code in Ionic and Angular....
Read more >
How To Use waitForAsync and fakeAsync with Angular Testing
Angular 2+ provides async and fakeAsync utilities for testing asynchronous code. This should make your Angular unit and integration tests ...
Read more >

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found