Skip to content

Commit afb59f7

Browse files
authored
Update test cases to use waitForAsync
Refactor test setup to use waitForAsync for asynchronous operations.
1 parent c75022d commit afb59f7

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/app/submission/sections/upload/file/view/section-upload-file-view.component.spec.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
} from '@angular/core/testing';
1212
import { TranslateModule } from '@ngx-translate/core';
1313

14+
import { LocaleService } from '../../../../../core/locale/locale.service';
1415
import { Metadata } from '../../../../../core/shared/metadata.utils';
1516
import { FormComponent } from '../../../../../shared/form/form.component';
1617
import { mockUploadFiles } from '../../../../../shared/mocks/submission.mock';
@@ -24,6 +25,12 @@ describe('SubmissionSectionUploadFileViewComponent test suite', () => {
2425
let comp: SubmissionSectionUploadFileViewComponent;
2526
let compAsAny: any;
2627
let fixture: ComponentFixture<SubmissionSectionUploadFileViewComponent>;
28+
let localeService: any;
29+
const languageList = ['en;q=1', 'de;q=0.8'];
30+
const mockLocaleService = jasmine.createSpyObj('LocaleService', {
31+
getCurrentLanguageCode: jasmine.createSpy('getCurrentLanguageCode'),
32+
getLanguageCodeList: of(languageList),
33+
});
2734

2835
const fileData: any = mockUploadFiles[0];
2936

@@ -38,6 +45,7 @@ describe('SubmissionSectionUploadFileViewComponent test suite', () => {
3845
],
3946
providers: [
4047
SubmissionSectionUploadFileViewComponent,
48+
{ provide: LocaleService, useValue: mockLocaleService },
4149
],
4250
schemas: [NO_ERRORS_SCHEMA],
4351
})
@@ -56,14 +64,15 @@ describe('SubmissionSectionUploadFileViewComponent test suite', () => {
5664
let testComp: TestComponent;
5765
let testFixture: ComponentFixture<TestComponent>;
5866

59-
// synchronous beforeEach
60-
beforeEach(() => {
67+
beforeEach(waitForAsync(async () => {
6168
const html = `
6269
<ds-submission-section-upload-file-view [fileData]="fileData"></ds-submission-section-upload-file-view>`;
6370

6471
testFixture = createTestComponent(html, TestComponent) as ComponentFixture<TestComponent>;
72+
localeService = TestBed.inject(LocaleService);
73+
localeService.getCurrentLanguageCode.and.returnValue(of('en'));
6574
testComp = testFixture.componentInstance;
66-
});
75+
}));
6776

6877
afterEach(() => {
6978
testFixture.destroy();
@@ -77,11 +86,13 @@ describe('SubmissionSectionUploadFileViewComponent test suite', () => {
7786
});
7887

7988
describe('', () => {
80-
beforeEach(() => {
89+
beforeEach(waitForAsync(async () => {
90+
localeService = TestBed.inject(LocaleService);
91+
localeService.getCurrentLanguageCode.and.returnValue(of('en'));
8192
fixture = TestBed.createComponent(SubmissionSectionUploadFileViewComponent);
8293
comp = fixture.componentInstance;
8394
compAsAny = comp;
84-
});
95+
}));
8596

8697
afterEach(() => {
8798
fixture.destroy();

0 commit comments

Comments
 (0)