Здравствуйте, я выполняю тестирование на моем файле login.component.spec.ts, и я получаю сообщение об ошибке
Failed: Uncaught (в обещании): ReferenceError: toastr не определен
и не в состоянии понять, где проблема
`login.component.spec.ts `:
import { async, ComponentFixture, TestBed ,inject} from '@angular/core/testing';
import {DebugElement} from '@angular/core';
import {FormsModule,FormGroup,ReactiveFormsModule} from '@angular/forms';
import { LoginComponent } from './login.component';
import { By,BrowserModule } from '@angular/platform-browser';
import { NgxLoadingModule } from 'ngx-loading';
import { RouterModule } from '@angular/router';
import { routes } from '../../app.routing';
import { P404Component } from '../../views/error/404.component';
import {P500Component} from '../../views/error/500.component';
import {RegisterComponent} from '../register/register.component';
import {ForgotPasswordComponent} from '../forgot-password/forgot-password/forgot-password.component';
import {ResetpasswordComponent} from '../resetpassword/resetpassword.component';
import {ChangepasswordComponent} from '../changepassword/changepassword.component';
import {DefaultLayoutComponent} from '../../containers/default-layout/default-layout.component' ;
import {AppAsideModule,AppBreadcrumbModule,AppHeaderModule,AppFooterModule,AppSidebarModule,
} from '@coreui/angular';
import { PerfectScrollbarModule } from 'ngx-perfect-scrollbar';
import { APP_BASE_HREF } from '@angular/common';
import { HttpClientModule,HttpClient } from '@angular/common/http';
// import { ToasterService } from '../../services/toaster.service';
import { ToasterService } from '../../services/toaster.service';
describe('LoginComponent', () => {
let component:LoginComponent ;
let fixture: ComponentFixture<LoginComponent>;
let de:DebugElement;
let el:HTMLElement;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ LoginComponent,
RegisterComponent,
ForgotPasswordComponent,
ResetpasswordComponent,
ChangepasswordComponent,
DefaultLayoutComponent,
P404Component,
P500Component],
imports:[
HttpClientModule,
RouterModule.forRoot(routes),
FormsModule,
BrowserModule,
NgxLoadingModule,
ReactiveFormsModule,
AppAsideModule,
AppBreadcrumbModule,
AppHeaderModule,
AppFooterModule,
AppSidebarModule,
PerfectScrollbarModule,
] ,
providers:[ ToasterService, { provide: APP_BASE_HREF, useValue: '/' }],
})
.compileComponents().then(() =>{
fixture = TestBed.createComponent(LoginComponent);
component = fixture.componentInstance;
de=fixture.debugElement.query(By.css('form'));
// el=de.nativeElement;
});
}));
beforeEach(() => {
fixture = TestBed.createComponent(LoginComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
Получение выхода как это:
Failed: Uncaught (в обещании): ReferenceError: toastr не определен
ReferenceError: toastr не определен
на ToasterService.setting (веб-пакет: ///./src/app/services/toaster.service.ts?: 27: 9)
на новом ToasterService (веб-пакет: ///./src/app/services/toaster.service.ts?: 15: 14)
в _createClass (веб-пакет: ///./node_modules/@angular/core/fesm5/core.js?: 8710: 20)
в _createProviderInstance (веб-пакет: ///./node_modules/@angular/core/fesm5/core.js?: 8684: 26)
at resolNgModuleDep (веб-пакет: ///./node_modules/@angular/core/fesm5/core.js?: 8647: 21)
в NgModuleRef_.get (веб-пакет: ///./node_modules/@angular/core/fesm5/core.js?: 9355: 16)
at resolDep (веб-пакет: ///./node_modules/@angular/core/fesm5/core.js?: 9720: 45)
at createClass (веб-пакет: ///./node_modules/@angular/core/fesm5/core.js?: 9600: 32)
at createDirectiveInstance (веб-пакет: ///./node_modules/@angular/core/fesm5/core.js?: 9477: 20)
в createViewNodes (веб-пакет: ///./node_modules/@angular/core/fesm5/core.js?: 10697: 36)
toaster.service.ts
import { Injectable } from '@angular/core';
declare var toastr:any;
@Injectable()
export class ToasterService {
constructor() {
this.setting();
}
Info(title:string)
{
toastr.info(title);
}
Success(title:string)
{
toastr.success(title);
}
Error(title:string){
toastr.error(title);
}
setting()
{
toastr.options = {
"closeButton": false,
"debug": false,
"newestOnTop": false,
"progressBar": false,
"positionClass": "toast-top-right",
"preventDuplicates": false,
"onclick": null,
"showDuration": "300",
"hideDuration": "1000",
"timeOut": "1800",
"extendedTimeOut": "1000",
"showEasing": "swing",
"hideEasing": "linear",
"showMethod": "fadeIn",
"hideMethod": "fadeOut"
}
}
}