Я всегда получаю эту ошибку случайно для разных тестов, когда я включаю свои тесты login.spec.ts. Uncaught Ошибка: Uncaught (в обещании): Ошибка: не может соответствовать ни один маршрут.Сегмент URL: 'logout'
Я попытался подделать метод выхода из системы в authService, используя: spyOn (authService, 'logout'). And.returnValues (true);Но все равно это не работает.Пожалуйста, помогите разобраться с проблемой здесь.
login.component.ts
export class LoginComponent implements OnInit {
isLoggingIn = false;
constructor(
private authService: AuthService
) { }
ngOnInit() {
this.authService.logout();
}
}
authService.ts
@Injectable()
export class AuthService {
public userSource: BehaviorSubject<string | undefined> = new BehaviorSubject<string | undefined>(undefined);
constructor(
private myRoute: Router) {
}
logout() { // TODO: Right now this is fake logout. We need to either destroy express session or cookie.
this.userSource.next(undefined);
this.myRoute.navigate(['logout']);
}
}
и теперь мой
логин.component.spec.ts
describe('LoginComponent', () => {
let component: LoginComponent;
let fixture: ComponentFixture<LoginComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ LoginComponent ],
providers: [ AuthService,
ConfigService
],
imports: [ RouterTestingModule,
HttpClientTestingModule ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(LoginComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});