How to fix "Error: Expected to be running in 'ProxyZone', but it was not found." in mocha testing?

how to fix anything
how to fix phone
how to fix a zipper
how to fix broken things
how to fix a computer
how to fix keyboard
ifixit
how to fix things around the house

I am trying to test my Tour of Heroes Angular application using mocha, chai & webpack. I have followed this post & also with the help of this guide, have gone through the setup and got the build errors fixed and tests up and running.

But, my tests fails except for the test case where i don't use the async() in the beforeEach hook.

Passing Test
  beforeEach(() => {
    TestBed.configureTestingModule({
      imports: [HttpClientTestingModule],
      providers: [HeroService, MessageService]
    });
    httpTestingController = TestBed.get(HttpTestingController);

    let mockHeroes = [...mockData];
    let mockHero = mockHeroes[0];
    // let mockId = mockHero.id;

    heroService = TestBed.get(HeroService);
  });

  afterEach(() => {
    httpTestingController.verify();
  });

  it('is created', () => {
    expect(heroService).to.exist;
  });

Failing Test
//imports
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { DashboardComponent } from './dashboard.component';
import { HeroSearchComponent } from '../hero-search/hero-search.component';

import { RouterTestingModule } from '@angular/router/testing';
import { HeroService } from '../hero.service';
import { expect } from 'chai';

...

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [DashboardComponent, HeroSearchComponent],
      imports: [RouterTestingModule.withRoutes([])],
      providers: [{ provide: HeroService, useValue: heroService }]
    }).compileComponents();
  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(DashboardComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });

  it('should be created', () => {
    expect(component).to.exist;
  });

Error Stack Trace

1) DashboardComponent

  "before each" hook for "should be created":
Error: Expected to be running in 'ProxyZone', but it was not found.
 at Function.ProxyZoneSpec.assertPresent (node_modules\zone.js\dist\proxy.js:42:19)
 at runInTestZone (node_modules\zone.js\dist\async-test.js:202:23)
 at D:\Practice\Tour-Of-Heroes\node_modules\zone.js\dist\async-test.js:185:17
 at new ZoneAwarePromise (node_modules\zone.js\dist\zone-node.js:910:29)
 at Context.<anonymous> (node_modules\zone.js\dist\async-test.js:184:20)

I have tried Angular 5 Testing: Expected to be running in 'ProxyZone', but it was not found as I thought this was some error with zone.js using mocha, but without success.

Also, I have tried following Mocha Documentation for asynchronous testing, but as a beginner, it was somewhat hard for me.

I have tried googling and even in stack-overflow, but there are only a limited amount of posts regarding Angular testing with mocha. Any help getting through this is appreciated.

I had the same issue and removing async from beforeEach (and it) solved the problem. The error message is not helpful at all, but I guess is not easy from where it is generated to detect what the root cause is.

iFixit: The Free Repair Manual, Most things around us eventually break down and need to be fixed. Learn essential DIY repair Duration: 14:27 Posted: 27 Jul 2019 So Windows 10 won't load. Or maybe it starts up, but crashes a lot. Either way, you need to fix the problem before you can use your laptop.If your screen is rotated, we have an easy fix for that

Here is the answer to this question.

Angular 5 Testing: Expected to be running in 'ProxyZone', but it was not found

Basically this exception is coming because of the incorrect position of an async keyword. Remove the async from beforeEach and add it on "it"

it('should be created', fakeAsync(() => {
    expect(component).to.exist;
  });

How to Fix ANYTHING, Timestamps 00:01 Slime cleaning trick 02:29 Coca-cola rust removal 02:55 Wall repair trick 03 Duration: 13:56 Posted: 21 Apr 2020 iFixit is a global community of people helping each other repair things. Let's fix the world, one device at a time. Troubleshoot with experts in the Answers forum—and build your own how-to guides to share with the world.

I had the same issue when accidentally using fakeAsync in a describe function.

Removed it solved the issue for me.

How To Repair Almost Everything, Umbra visits the Fixers' Collective in Brooklyn, a social experiment in improvisational fixing Duration: 2:53 Posted: 9 Mar 2010 P ress the Windows key, type Network problems, and then select Identify and repair network problems in the list. Follow the steps in the wizard to diagnose and resolve your network problems. Run Windows Update again.

I see a few issues here.

You have 2 beforeEach. You should only have 1. If you have async on your block of test code, then you need to call await on a function, and/or use flush or tick to progress time. I usually use fakeAsync for observables, and async/await for real async methods.

For this specific example, you shouldn't need the async at all.

How to Fix Everything, How To FIX YOUR PHONE In SECONDS! If you enjoyed this video, watch more here:�Duration: 11:40 Posted: 9 Oct 2019 People Helping People Fix Stuff. Help is here! Learn how to do your own repairs and save money! This site is filled with articles written by skilled individuals. You will find step by step "How To", tips and tricks, and general guidance on fixing your stuff. Finding Solutions

How To FIX YOUR PHONE In SECONDS! (Reacting To Life Hacks , Bad back, blotchy skin, and a wobbly feeling in your gut? Our anatomies are feeling the strain of too long spent at home. If an Office application such as Word or Excel isn’t working correctly, sometimes restarting it will fix the problem. If that doesn’t work, you can try repairing it. When you’re done, you might need to restart your computer. Repair Office from the Control Panel. The steps to access the repair tool vary depending on your operating system.

What lockdown has done to our bodies – and how to fix it, Click on the category image of the appliance that you have a problem with. Find your Repair guide. Make shore your watch the right tutorial. Then find the spare� Fix your internet. Screenshot by David Priest/CNET. OK, this is the hard part. Even if you find out your provider is throttling your internet, there may not be much you can actually do. Many

How to Repair, Buy How to Fix (Just About) Everything: More Than 550 Step-By-Step Instructions for Everything from Fixing a Faucet to Removing Mystery Stains to Curing a by� Repairing nasty leather or vinyl seating. This repair will last you for years and years. This video shows you how to fix cracks and rips in your upholstery and then recolor them to be perfect again.

Comments
  • same problem here
  • 5th Angular specific error I've hit today. This framework is such a timesink.
  • Ya the problem is I needed to test for asynchronous code and removing async is not an option when coming to that part.