datasurvey/src/main/webapp/app/shared/alert/alert.component.spec.ts

49 lines
1.2 KiB
TypeScript
Raw Normal View History

2021-07-03 21:48:27 +00:00
jest.mock('app/core/util/alert.service');
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { AlertService } from 'app/core/util/alert.service';
import { AlertComponent } from './alert.component';
describe('Component Tests', () => {
describe('Alert Component', () => {
let comp: AlertComponent;
let fixture: ComponentFixture<AlertComponent>;
let mockAlertService: AlertService;
beforeEach(
waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [AlertComponent],
providers: [AlertService],
})
.overrideTemplate(AlertComponent, '')
.compileComponents();
})
);
beforeEach(() => {
fixture = TestBed.createComponent(AlertComponent);
comp = fixture.componentInstance;
mockAlertService = TestBed.inject(AlertService);
});
it('Should call alertService.get on init', () => {
// WHEN
comp.ngOnInit();
// THEN
expect(mockAlertService.get).toHaveBeenCalled();
});
it('Should call alertService.clear on destroy', () => {
// WHEN
comp.ngOnDestroy();
// THEN
expect(mockAlertService.clear).toHaveBeenCalled();
});
});
});