I am currently using Angular 7 with the Zone.js version of approximately ~0.8.26. Inside my test.ts file, I have included the import statement for 'zone.js/dist/zone-testing'. Below is a snippet from my spec file:
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { CUSTOM_ELEMENTS_SCHEMA, DebugElement } from '@angular/core';
import { async, fakeAsync, flushMicrotasks, tick, ComponentFixture, TestBed } from '@angular/core/testing';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { MatAutocompleteModule, MatDatepickerModule, MatNativeDateModule } from '@angular/material';
import { By } from '@angular/platform-browser';
import { RouterTestingModule } from '@angular/router/testing';
import { of } from 'rxjs';
import { CustomPipesModule } from 'shared/custom-pipes.module';
import { GoogleAutocompletePrediction } from 'shared/models';
import { DataService } from 'shared/services/data.service';
import { GoogleMapsService } from 'shared/services/google-maps.service';
import { I18nConstantsService } from 'shared/services/i18n-constants.service';
import { InsuranceService } from 'shared/services/insurance.service';
import { MockI18nModule } from 'shared/specs/mocks/I18n/mock-i18n.module';
import { MockDataService } from 'shared/specs/mocks/mock-data.service';
import { mockAutocompletePrediction, MockGoogleMapsService } from 'shared/specs/mocks/mock-google-maps.service';
import { MockInsuranceService } from 'shared/specs/mocks/mock-insurance.service';
import { AsInsuranceInformationComponent } from './as-insurance-information.component';
const debounceTime = 200;
const mockPredictions = new Array(5).fill(new GoogleAutocompletePrediction());
describe('AsInsuranceInformationComponent', () => {
let component: AsInsuranceInformationComponent;
let fixture: ComponentFixture<AsInsuranceInformationComponent>;
let insuranceService: InsuranceService;
let googleService: GoogleMapsService;
let dataService: DataService;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [AsInsuranceInformationComponent],
imports: [RouterTestingModule,
HttpClientTestingModule,
MatAutocompleteModule,
FormsModule,
ReactiveFormsModule,
CustomPipesModule,
MockI18nModule,
MatDatepickerModule,
MatNativeDateModule],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
providers: [I18nConstantsService,
{ provide: InsuranceService, useClass: MockInsuranceService },
{ provide: GoogleMapsService, useClass: MockGoogleMapsService },
{ provide: DataService, useClass: MockDataService }
]
})
.compileComponents();
}));
beforeEach(() => {
googleService = TestBed.get(GoogleMapsService);
insuranceService = TestBed.get(InsuranceService);
fixture = TestBed.createComponent(AsInsuranceInformationComponent);
component = fixture.componentInstance;
// Additional setup for insuranceProviders data
...
fixture.detectChanges();
});
fdescribe('auto complete diff address', () => {
beforeEach(
fakeAsync(() => {
// Setting up initial values for testing
...
}));
it(
'debounces the input',
fakeAsync(() => {
// Test case for debouncing input
...
})
);
it(
'does autofill city and state',
fakeAsync(() => {
// Test case for auto-filling city and state based on postal code
...
})
);
});
});
However, I keep encountering this error in Chrome:
Uncaught Error: macroTask 'setInterval': can not transition to 'running', expecting state 'scheduled', was 'notScheduled'.
The console is filled with recursive errors as well.
In the component file, there is a function that I'm trying to test:
zipCodeValidationDiffAddressInit() {
// Implementation code for zip code validation
...
}
If you have any insights or suggestions on how to resolve this issue, they would be greatly appreciated.