Skip to content

Commit c5a8133

Browse files
committed
[DSC-1875] Improve test in order to avoid random failures
1 parent f5dc1c1 commit c5a8133

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/app/lucky-search/search/lucky-search.component.spec.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ describe('LuckySearchComponent', () => {
7878
index: 'test',
7979
'value': 'test'
8080
};
81-
const routerStub = new RouterMock();
81+
let routerStub = new RouterMock();
8282

8383
const bitstreamMetadata = {
8484
'dc.title': [{value: 'test.pdf'} as MetadataValue],
@@ -106,10 +106,8 @@ describe('LuckySearchComponent', () => {
106106
.compileComponents();
107107
});
108108

109-
beforeEach(() => {
110-
fixture = TestBed.createComponent(LuckySearchComponent);
111-
component = fixture.componentInstance;
112-
fixture.detectChanges();
109+
afterEach(() => {
110+
routerStub = new RouterMock();
113111
});
114112

115113
describe('should search items', () => {
@@ -284,6 +282,12 @@ describe('LuckySearchComponent', () => {
284282
});
285283
});
286284

285+
describe('', () => {
286+
beforeEach(() => {
287+
fixture = TestBed.createComponent(LuckySearchComponent);
288+
component = fixture.componentInstance;
289+
});
290+
287291
it('should not redirect when no bitstreams are found', () => {
288292
const item = Object.assign(new Item(), {uuid: 'item-uuid-1', name: 'Test item 1'});
289293
const data = createSuccessfulRemoteDataObject(createPaginatedList([
@@ -298,6 +302,7 @@ describe('LuckySearchComponent', () => {
298302
});
299303

300304
it('should update showEmptySearchSection$ when no results are found', () => {
305+
fixture.detectChanges();
301306
const emptyResults = createSuccessfulRemoteDataObject(createPaginatedList([]));
302307

303308
spyOn(component as any, 'getLuckySearchResults').and.returnValue(observableOf(emptyResults));
@@ -307,4 +312,6 @@ describe('LuckySearchComponent', () => {
307312

308313
expect(component.showEmptySearchSection$.getValue()).toBe(true);
309314
});
315+
316+
});
310317
});

0 commit comments

Comments
 (0)