1 import { ComponentFixture, TestBed } from '@angular/core/testing';
3 import { configureTestBed } from '~/testing/unit-test-helper';
4 import { TextToDownloadService } from '~/app/shared/services/text-to-download.service';
5 import { DownloadButtonComponent } from './download-button.component';
7 describe('DownloadButtonComponent', () => {
8 let component: DownloadButtonComponent;
9 let fixture: ComponentFixture<DownloadButtonComponent>;
12 declarations: [DownloadButtonComponent],
13 providers: [TextToDownloadService]
17 fixture = TestBed.createComponent(DownloadButtonComponent);
18 component = fixture.componentInstance;
19 fixture.detectChanges();
22 it('should create', () => {
23 expect(component).toBeTruthy();
26 it('should call download function', () => {
27 component.objectItem = {
31 const downloadSpy = spyOn(TestBed.inject(TextToDownloadService), 'download');
32 component.fileName = `${'reportText.json'}_${new Date().toLocaleDateString()}`;
33 component.download('json');
34 expect(downloadSpy).toHaveBeenCalledWith(
35 JSON.stringify(component.objectItem, null, 2),
36 `${component.fileName}.json`