An error was thrown in afterAll Uncaught ReferenceError: Cannot access
'MyComponentComponent' before initialization
I think this is due to a circular Зависимость, потому что мой компонент получает доступ к файлу маршрута, на котором ссылается сам компонент.
Код: Выделить всё
import {Component, OnInit} from '@angular/core';
import {myRoutes} from './my-routes';
@Component({
selector: 'mi-component',
template: ``,
})
export class MyComponentComponent implements OnInit {
ngOnInit(): void {
}
routesModification() {
const routes = myRoutes;
routes[0].path = '/new-route';
}
}
Код: Выделить всё
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {MyComponentComponent} from './my-component.component';
describe('MyComponentComponent class', () => {
let component: MyComponentComponent;
let fixture: ComponentFixture;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [MyComponentComponent],
imports: [],
providers: [],
}).compileComponents();
fixture = TestBed.createComponent(MyComponentComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('El componente deberia estar creado correctamente', () => {
expect(component).toBeTruthy();
});
});
import {Routes} from '@angular/router';
import {MyComponentComponent} from './my-component.component';
export const myRoutes: Routes = [
{
path: '',
component: MyComponentComponent,
},
];
< /code>
Мне нужно исправить это так, чтобы тест прошел, не касаясь компонента или файлов маршрута, которые мне не разрешают. Это проблема, которая возникает только тогда, когда я запускаю тест индивидуально, когда я запускаю приложение или когда я запускаю NG Test во всем мире, нет такого сообщения.
Подробнее здесь: https://stackoverflow.com/questions/795 ... in-jasmine