Skip to content

Commit 31dce16

Browse files
committed
fixed the tests
1 parent 14bc7f7 commit 31dce16

3 files changed

Lines changed: 31 additions & 19 deletions

File tree

projects/ngx-extended-pdf-viewer/src/lib/pdf-dummy-components/pdf-dummy-components.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ describe('PdfDummyComponentsComponent', () => {
238238
component.addMissingStandardWidgets();
239239

240240
// Should process each required ID
241-
expect(getElementByIdSpy).toHaveBeenCalledTimes(194); // Number of entries in requiredIds array (scaleSelect is included in the array)
241+
expect(getElementByIdSpy).toHaveBeenCalledTimes(195); // Number of entries in requiredIds array (scaleSelect is included in the array)
242242
});
243243

244244
it('should handle duplicate IDs in requiredIds array', () => {

projects/ngx-extended-pdf-viewer/src/lib/pdf-script-loader.service.spec.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -242,15 +242,18 @@ describe('PDFScriptLoaderService', () => {
242242
});
243243

244244
it('should return false in server-side rendering environment', () => {
245-
// Mock server-side environment
245+
// jsdom marks `window` on globalThis as non-configurable, so `delete`
246+
// fails — but it's still writable, so assigning undefined makes
247+
// `typeof window === 'undefined'` true for the guard under test.
246248
const originalWindow = (global as any).window;
247-
delete (global as any).window;
249+
(global as any).window = undefined;
248250

249-
const requiresES5 = (service as any).iOSVersionRequiresES5();
250-
expect(requiresES5).toBe(false);
251-
252-
// Restore window
253-
(global as any).window = originalWindow;
251+
try {
252+
const requiresES5 = (service as any).iOSVersionRequiresES5();
253+
expect(requiresES5).toBe(false);
254+
} finally {
255+
(global as any).window = originalWindow;
256+
}
254257
});
255258
});
256259

@@ -398,14 +401,17 @@ describe('PDFScriptLoaderService', () => {
398401
});
399402

400403
it('should handle server-side rendering environment', () => {
401-
// Mock server-side environment
404+
// jsdom marks `window` on globalThis as non-configurable, so `delete`
405+
// fails — but it's still writable, so assigning undefined makes
406+
// `typeof window === 'undefined'` true for the guard under test.
402407
const originalWindow = (global as any).window;
403-
delete (global as any).window;
404-
405-
expect(() => service.ngOnDestroy()).not.toThrow();
408+
(global as any).window = undefined;
406409

407-
// Restore window
408-
(global as any).window = originalWindow;
410+
try {
411+
expect(() => service.ngOnDestroy()).not.toThrow();
412+
} finally {
413+
(global as any).window = originalWindow;
414+
}
409415
});
410416
});
411417

projects/ngx-extended-pdf-viewer/src/lib/secondary-toolbar/pdf-secondary-toolbar/pdf-secondary-toolbar.component.test.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -380,14 +380,20 @@ describe('PdfSecondaryToolbarComponent', () => {
380380

381381
describe('checkVisibilityRecursively', () => {
382382
it('should return 0 for server-side rendering', () => {
383+
// jsdom marks `window` on globalThis as non-configurable, so `delete`
384+
// fails — but it's still writable, so assigning undefined makes
385+
// `typeof window === 'undefined'` true for the guard under test.
383386
const originalWindow = global.window;
384-
delete (global as any).window;
387+
(global as any).window = undefined;
385388

386-
const element = document.createElement('div');
387-
const result = component['checkVisibilityRecursively'](element);
389+
try {
390+
const element = document.createElement('div');
391+
const result = component['checkVisibilityRecursively'](element);
388392

389-
expect(result).toBe(0);
390-
global.window = originalWindow;
393+
expect(result).toBe(0);
394+
} finally {
395+
global.window = originalWindow;
396+
}
391397
});
392398

393399
it('should return 0 for elements with display none style', () => {

0 commit comments

Comments
 (0)