import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ModalModule } from 'ngx-bootstrap/modal';
+import { BsModalRef } from 'ngx-bootstrap/modal/bs-modal-ref.service';
import { configureTestBed } from '../../../../testing/unit-test-helper';
import { ModalComponent } from './modal.component';
it('should create', () => {
expect(component).toBeTruthy();
});
+
+ it('should call the hide callback function', () => {
+ spyOn(component.hide, 'emit');
+ const nativeElement = fixture.nativeElement;
+ const button = nativeElement.querySelector('button');
+ button.dispatchEvent(new Event('click'));
+ fixture.detectChanges();
+ expect(component.hide.emit).toHaveBeenCalled();
+ });
+
+ it('should hide the modal', () => {
+ component.modalRef = new BsModalRef();
+ spyOn(component.modalRef, 'hide');
+ component.close();
+ expect(component.modalRef.hide).toHaveBeenCalled();
+ });
});
-import { Component, Input } from '@angular/core';
+import { Component, EventEmitter, Input, Output } from '@angular/core';
import { BsModalRef } from 'ngx-bootstrap/modal/bs-modal-ref.service';
@Input()
modalRef: BsModalRef;
+ /**
+ * Should be a function that is triggered when the modal is hidden.
+ */
+ @Output()
+ hide = new EventEmitter();
+
constructor() {}
+
+ close() {
+ if (this.modalRef) {
+ this.modalRef.hide();
+ }
+ this.hide.emit();
+ }
}