import { CommonModule } from '@angular/common'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { NgxSunViewComponent } from './ngx-sunview.component'; import { SafeHtmlPipe } from './safeHTML.pipe'; describe('NgxSunViewComponent', async () => { let component: NgxSunViewComponent; let fixture: ComponentFixture; beforeEach(async () => { await TestBed.configureTestingModule({ declarations: [NgxSunViewComponent, SafeHtmlPipe], imports: [CommonModule], }).compileComponents(); }); beforeEach(() => { fixture = TestBed.createComponent(NgxSunViewComponent); component = fixture.componentInstance; fixture.detectChanges(); }); it('should create the view', () => { expect(component).toBeTruthy(); }); it('should show content passed @Input ', () => { const content = '

Test content to show

'; component.content = content; fixture.detectChanges(); const element = document.querySelector('[class="sun-editor-editable"]'); expect(element.innerHTML).toEqual('

Test content to show

'); }); it('should not bypass DomSanitizer when passed false', () => { const content = `

Test content

`; component.content = content; component.bypassSantiziser = false; fixture.detectChanges(); const element = document.querySelector('[class="sun-editor-editable"]'); expect(element.innerHTML).toContain('

Test content

'); expect(element.innerHTML).not.toContain('script'); }); it('should bypass DomSanitizer when passed true', () => { const content = `

Test content

`; component.content = content; component.bypassSantiziser = true; fixture.detectChanges(); const element = document.querySelector('[class="sun-editor-editable"]'); expect(element.innerHTML).toContain('

Test content

'); expect(element.innerHTML).toContain('script'); }); });