From 22d687b769cba4a071f1129e8e1c6078d633178f Mon Sep 17 00:00:00 2001 From: Quentin Date: Sun, 26 Jan 2025 20:59:20 +0100 Subject: [PATCH 1/4] Tests: replace toHaveBeenCalledTimes(1) by toHaveBeenCalledOnce() --- .../primary/loginForm/index.test.tsx.mustache | 2 +- .../primary/loginModal/index.test.tsx.mustache | 2 +- .../common/primary/timeout/Timeout.spec.ts | 4 ++-- .../unit/common/primary/toast/Toast.spec.ts | 4 ++-- .../landscape/LandscapeComponent.spec.ts | 18 +++++++++--------- .../landscape/LandscapeScroller.spec.ts | 6 +++--- .../primary/WindowApplicationListener.spec.ts | 4 ++-- .../secondary/MittAlertBus.spec.ts | 4 ++-- .../secondary/MittAlertListener.spec.ts | 4 ++-- .../secondary/ConsoleLogger.spec.ts | 2 +- 10 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/main/resources/generator/client/react/security/jwt/src/test/webapp/unit/login/primary/loginForm/index.test.tsx.mustache b/src/main/resources/generator/client/react/security/jwt/src/test/webapp/unit/login/primary/loginForm/index.test.tsx.mustache index 3cac8855967..cbc45166d78 100644 --- a/src/main/resources/generator/client/react/security/jwt/src/test/webapp/unit/login/primary/loginForm/index.test.tsx.mustache +++ b/src/main/resources/generator/client/react/security/jwt/src/test/webapp/unit/login/primary/loginForm/index.test.tsx.mustache @@ -49,7 +49,7 @@ describe('loginForm', () => { const spy = mockPost(); await login(); - expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledOnce(); }); it('should display Log out after login and display Log in after logout', async () => { diff --git a/src/main/resources/generator/client/react/security/jwt/src/test/webapp/unit/login/primary/loginModal/index.test.tsx.mustache b/src/main/resources/generator/client/react/security/jwt/src/test/webapp/unit/login/primary/loginModal/index.test.tsx.mustache index 1eb9523bd64..090116019db 100644 --- a/src/main/resources/generator/client/react/security/jwt/src/test/webapp/unit/login/primary/loginModal/index.test.tsx.mustache +++ b/src/main/resources/generator/client/react/security/jwt/src/test/webapp/unit/login/primary/loginModal/index.test.tsx.mustache @@ -68,7 +68,7 @@ describe('test login modal', () => { const submitButton = getByTestId('submit-button'); fireEvent.click(submitButton); }); - expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledOnce(); }); it('render the modal on login button click and close the modal on close button', async () => { diff --git a/src/test/webapp/unit/common/primary/timeout/Timeout.spec.ts b/src/test/webapp/unit/common/primary/timeout/Timeout.spec.ts index 935e84adab5..590c8d0e5f6 100644 --- a/src/test/webapp/unit/common/primary/timeout/Timeout.spec.ts +++ b/src/test/webapp/unit/common/primary/timeout/Timeout.spec.ts @@ -19,7 +19,7 @@ describe('Timeout', () => { vi.advanceTimersByTime(TIMEOUT_TIME); - expect(stub).toHaveBeenCalledTimes(1); + expect(stub).toHaveBeenCalledOnce(); }); it('should not launch timeout with less some time', () => { @@ -59,6 +59,6 @@ describe('Timeout', () => { vi.advanceTimersByTime(TIMEOUT_TIME); expect(firstCall).toHaveBeenCalledTimes(0); - expect(secondCall).toHaveBeenCalledTimes(1); + expect(secondCall).toHaveBeenCalledOnce(); }); }); diff --git a/src/test/webapp/unit/common/primary/toast/Toast.spec.ts b/src/test/webapp/unit/common/primary/toast/Toast.spec.ts index 4c24ba18a9b..3183f950f79 100644 --- a/src/test/webapp/unit/common/primary/toast/Toast.spec.ts +++ b/src/test/webapp/unit/common/primary/toast/Toast.spec.ts @@ -97,8 +97,8 @@ describe('Toast', () => { wrapper.unmount(); - expect(unsubscribeSuccess).toHaveBeenCalledTimes(1); - expect(unsubscribeError).toHaveBeenCalledTimes(1); + expect(unsubscribeSuccess).toHaveBeenCalledOnce(); + expect(unsubscribeError).toHaveBeenCalledOnce(); }); describe('Timeout', () => { diff --git a/src/test/webapp/unit/module/primary/landscape/LandscapeComponent.spec.ts b/src/test/webapp/unit/module/primary/landscape/LandscapeComponent.spec.ts index 6af97b4a255..6729f380451 100644 --- a/src/test/webapp/unit/module/primary/landscape/LandscapeComponent.spec.ts +++ b/src/test/webapp/unit/module/primary/landscape/LandscapeComponent.spec.ts @@ -209,7 +209,7 @@ describe('Landscape', () => { expect(wrapper.find(wrappedElement('landscape-loader')).exists()).toBe(false); expect(wrapper.find(wrappedElement('landscape')).exists()).toBe(true); expect(wrapper.find(wrappedElement('landscape-connectors')).findAll('path').length).toBe(17); - expect(applicationListener.addEventListener).toHaveBeenCalledTimes(1); + expect(applicationListener.addEventListener).toHaveBeenCalledOnce(); const pathField = wrapper.find(wrappedElement('folder-path-field')).element as HTMLInputElement; expect(pathField.value).toBe('/tmp/jhlite/1234'); @@ -221,7 +221,7 @@ describe('Landscape', () => { wrapper.unmount(); - expect(applicationListener.removeEventListener).toHaveBeenCalledTimes(1); + expect(applicationListener.removeEventListener).toHaveBeenCalledOnce(); }); it('should load folder path from local storage', async () => { @@ -845,7 +845,7 @@ describe('Landscape', () => { const landscape = wrapper.find(wrappedElement('landscape-container')); await landscape.trigger('mousedown', mouseEvent); - expect(cursorUpdater.set).toHaveBeenCalledTimes(1); + expect(cursorUpdater.set).toHaveBeenCalledOnce(); expect(cursorUpdater.set).toBeCalledWith('grabbing'); }); @@ -863,7 +863,7 @@ describe('Landscape', () => { const landscape = wrapper.find(wrappedElement('landscape-container')); await landscape.trigger('mousedown', mouseEvent); - expect(mouseEvent.preventDefault).toHaveBeenCalledTimes(1); + expect(mouseEvent.preventDefault).toHaveBeenCalledOnce(); }); it('should stop grabbing on mouseup', async () => { @@ -875,7 +875,7 @@ describe('Landscape', () => { const landscape = wrapper.find(wrappedElement('landscape-container')); await landscape.trigger('mouseup'); - expect(cursorUpdater.reset).toHaveBeenCalledTimes(1); + expect(cursorUpdater.reset).toHaveBeenCalledOnce(); }); it('should stop grabbing on mouseleave', async () => { @@ -887,7 +887,7 @@ describe('Landscape', () => { const landscape = wrapper.find(wrappedElement('landscape-container')); await landscape.trigger('mouseleave'); - expect(cursorUpdater.reset).toHaveBeenCalledTimes(1); + expect(cursorUpdater.reset).toHaveBeenCalledOnce(); }); it('should be scrolling', async () => { @@ -909,7 +909,7 @@ describe('Landscape', () => { await landscape.trigger('mousedown', mouseEventStart); await landscape.trigger('mousemove', mouseEventGrabbed); - expect(landscapeScroller.scroll).toHaveBeenCalledTimes(1); + expect(landscapeScroller.scroll).toHaveBeenCalledOnce(); expect(landscapeScroller.scroll).toBeCalledWith(expect.anything(), 20, 20); }); @@ -1277,7 +1277,7 @@ describe('Landscape', () => { expect(mockModuleRect).toHaveBeenCalled(); expect(mockContainerRect).toHaveBeenCalled(); - expect(landscapeScroller.scrollIntoView).toHaveBeenCalledTimes(1); + expect(landscapeScroller.scrollIntoView).toHaveBeenCalledOnce(); expect(landscapeScroller.scrollIntoView).toHaveBeenCalledWith(prettierModule); }); @@ -1321,7 +1321,7 @@ describe('Landscape', () => { await performSearch(searchInput, ''); - expect(landscapeScroller.scrollSmooth).toHaveBeenCalledTimes(1); + expect(landscapeScroller.scrollSmooth).toHaveBeenCalledOnce(); expect(landscapeScroller.scrollSmooth).toHaveBeenCalledWith(landscapeContainer, 0, 0); }); diff --git a/src/test/webapp/unit/module/primary/landscape/LandscapeScroller.spec.ts b/src/test/webapp/unit/module/primary/landscape/LandscapeScroller.spec.ts index 394d786c496..a2a6dc3f41f 100644 --- a/src/test/webapp/unit/module/primary/landscape/LandscapeScroller.spec.ts +++ b/src/test/webapp/unit/module/primary/landscape/LandscapeScroller.spec.ts @@ -18,7 +18,7 @@ describe('LandscapeScroller', () => { landscapeScroller.scroll(element, 10, 10); - expect(element.scroll).toHaveBeenCalledTimes(1); + expect(element.scroll).toHaveBeenCalledOnce(); expect(element.scroll).toBeCalledWith(10, 10); }); @@ -28,7 +28,7 @@ describe('LandscapeScroller', () => { landscapeScroller.scrollSmooth(element, 10, 10); - expect(element.scroll).toHaveBeenCalledTimes(1); + expect(element.scroll).toHaveBeenCalledOnce(); expect(element.scroll).toBeCalledWith({ left: 10, top: 10, behavior: 'smooth' }); }); @@ -38,7 +38,7 @@ describe('LandscapeScroller', () => { landscapeScroller.scrollIntoView(element); - expect(element.scrollIntoView).toHaveBeenCalledTimes(1); + expect(element.scrollIntoView).toHaveBeenCalledOnce(); expect(element.scrollIntoView).toBeCalledWith({ behavior: 'smooth', block: 'center', inline: 'center' }); }); }); diff --git a/src/test/webapp/unit/shared/alert/infrastructure/primary/WindowApplicationListener.spec.ts b/src/test/webapp/unit/shared/alert/infrastructure/primary/WindowApplicationListener.spec.ts index e41af011d51..82dc0e32968 100644 --- a/src/test/webapp/unit/shared/alert/infrastructure/primary/WindowApplicationListener.spec.ts +++ b/src/test/webapp/unit/shared/alert/infrastructure/primary/WindowApplicationListener.spec.ts @@ -9,7 +9,7 @@ describe('WindowApplicationListener', () => { windowApplicationListener.addEventListener('success', () => {}); - expect(window.addEventListener).toHaveBeenCalledTimes(1); + expect(window.addEventListener).toHaveBeenCalledOnce(); }); it('should remove event listener on window', () => { @@ -19,6 +19,6 @@ describe('WindowApplicationListener', () => { windowApplicationListener.removeEventListener('success', () => {}); - expect(window.removeEventListener).toHaveBeenCalledTimes(1); + expect(window.removeEventListener).toHaveBeenCalledOnce(); }); }); diff --git a/src/test/webapp/unit/shared/alert/infrastructure/secondary/MittAlertBus.spec.ts b/src/test/webapp/unit/shared/alert/infrastructure/secondary/MittAlertBus.spec.ts index b9179fa803a..95de60e36be 100644 --- a/src/test/webapp/unit/shared/alert/infrastructure/secondary/MittAlertBus.spec.ts +++ b/src/test/webapp/unit/shared/alert/infrastructure/secondary/MittAlertBus.spec.ts @@ -10,7 +10,7 @@ describe('MittAlertBus', () => { mittAlertBus.success('A message'); - expect(emitterStub.emit).toHaveBeenCalledTimes(1); + expect(emitterStub.emit).toHaveBeenCalledOnce(); expect(emitterStub.emit).toBeCalledWith(AlertType.SUCCESS, 'A message'); }); @@ -20,7 +20,7 @@ describe('MittAlertBus', () => { mittAlertBus.error('A message'); - expect(emitterStub.emit).toHaveBeenCalledTimes(1); + expect(emitterStub.emit).toHaveBeenCalledOnce(); expect(emitterStub.emit).toBeCalledWith(AlertType.ERROR, 'A message'); }); }); diff --git a/src/test/webapp/unit/shared/alert/infrastructure/secondary/MittAlertListener.spec.ts b/src/test/webapp/unit/shared/alert/infrastructure/secondary/MittAlertListener.spec.ts index 9b91059b9fa..175958507c2 100644 --- a/src/test/webapp/unit/shared/alert/infrastructure/secondary/MittAlertListener.spec.ts +++ b/src/test/webapp/unit/shared/alert/infrastructure/secondary/MittAlertListener.spec.ts @@ -12,7 +12,7 @@ describe('MittAlertListener', () => { emitter.emit(AlertType.SUCCESS, 'A message'); - expect(spyAlerted).toHaveBeenCalledTimes(1); + expect(spyAlerted).toHaveBeenCalledOnce(); expect(spyAlerted).toBeCalledWith('A message'); }); @@ -39,7 +39,7 @@ describe('MittAlertListener', () => { emitter.emit(AlertType.ERROR, 'A message'); - expect(spyAlerted).toHaveBeenCalledTimes(1); + expect(spyAlerted).toHaveBeenCalledOnce(); expect(spyAlerted).toBeCalledWith('A message'); }); diff --git a/src/test/webapp/unit/shared/logger/infrastructure/secondary/ConsoleLogger.spec.ts b/src/test/webapp/unit/shared/logger/infrastructure/secondary/ConsoleLogger.spec.ts index 3811d769a5a..03340e50f16 100644 --- a/src/test/webapp/unit/shared/logger/infrastructure/secondary/ConsoleLogger.spec.ts +++ b/src/test/webapp/unit/shared/logger/infrastructure/secondary/ConsoleLogger.spec.ts @@ -11,7 +11,7 @@ describe('ConsoleLogger', () => { consoleLogger.error('An error occurs', error); - expect(logger.error).toHaveBeenCalledTimes(1); + expect(logger.error).toHaveBeenCalledOnce(); expect(logger.error).toBeCalledWith('An error occurs\n', error); }); }); From 806187aded90ca09ad5f46f96a9e0aa9b90a107d Mon Sep 17 00:00:00 2001 From: Quentin Date: Sun, 26 Jan 2025 21:02:35 +0100 Subject: [PATCH 2/4] Tests: replace toHaveBeenCalledTimes(0) by not.toHaveBeenCalled() --- .../unit/login/primary/loginModal/index.test.tsx.mustache | 2 +- src/test/webapp/unit/common/primary/timeout/Timeout.spec.ts | 6 +++--- .../module/primary/landscape/LandscapeComponent.spec.ts | 4 ++-- .../primary/landscape/LandscapeMiniMapComponent.spec.ts | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/resources/generator/client/react/security/jwt/src/test/webapp/unit/login/primary/loginModal/index.test.tsx.mustache b/src/main/resources/generator/client/react/security/jwt/src/test/webapp/unit/login/primary/loginModal/index.test.tsx.mustache index 090116019db..1bc396e2124 100644 --- a/src/main/resources/generator/client/react/security/jwt/src/test/webapp/unit/login/primary/loginModal/index.test.tsx.mustache +++ b/src/main/resources/generator/client/react/security/jwt/src/test/webapp/unit/login/primary/loginModal/index.test.tsx.mustache @@ -85,7 +85,7 @@ describe('test login modal', () => { const submitButton = getByRole('button', { name: 'Close' }); fireEvent.click(submitButton); }); - expect(spy).toHaveBeenCalledTimes(0); + expect(spy).not.toHaveBeenCalled(); }); it('should contain error message when submit button is clicked with empty value', async () => { diff --git a/src/test/webapp/unit/common/primary/timeout/Timeout.spec.ts b/src/test/webapp/unit/common/primary/timeout/Timeout.spec.ts index 590c8d0e5f6..d2dc97e8051 100644 --- a/src/test/webapp/unit/common/primary/timeout/Timeout.spec.ts +++ b/src/test/webapp/unit/common/primary/timeout/Timeout.spec.ts @@ -28,7 +28,7 @@ describe('Timeout', () => { vi.advanceTimersByTime(LESS_TIME); - expect(stub).toHaveBeenCalledTimes(0); + expect(stub).not.toHaveBeenCalled(); }); it('should not launch timeout with unsubscribe', () => { @@ -39,7 +39,7 @@ describe('Timeout', () => { timeout.unregister(); vi.advanceTimersByTime(TIMEOUT_TIME); - expect(stub).toHaveBeenCalledTimes(0); + expect(stub).not.toHaveBeenCalled(); }); it('should not fail to unregister when not registered', () => { @@ -58,7 +58,7 @@ describe('Timeout', () => { timeout.register(secondCall, TIMEOUT_TIME); vi.advanceTimersByTime(TIMEOUT_TIME); - expect(firstCall).toHaveBeenCalledTimes(0); + expect(firstCall).not.toHaveBeenCalled(); expect(secondCall).toHaveBeenCalledOnce(); }); }); diff --git a/src/test/webapp/unit/module/primary/landscape/LandscapeComponent.spec.ts b/src/test/webapp/unit/module/primary/landscape/LandscapeComponent.spec.ts index 6729f380451..2b9bb13940f 100644 --- a/src/test/webapp/unit/module/primary/landscape/LandscapeComponent.spec.ts +++ b/src/test/webapp/unit/module/primary/landscape/LandscapeComponent.spec.ts @@ -744,7 +744,7 @@ describe('Landscape', () => { const consoleErrors = vi.spyOn(console, 'error'); await updatePath(wrapper); - expect(console.error).toHaveBeenCalledTimes(0); + expect(console.error).not.toHaveBeenCalled(); consoleErrors.mockRestore(); }); @@ -926,7 +926,7 @@ describe('Landscape', () => { const landscape = wrapper.find(wrappedElement('landscape-container')); await landscape.trigger('mousemove', mouseEventGrabbed); - expect(landscapeScroller.scroll).toHaveBeenCalledTimes(0); + expect(landscapeScroller.scroll).not.toHaveBeenCalled(); }); }); diff --git a/src/test/webapp/unit/module/primary/landscape/LandscapeMiniMapComponent.spec.ts b/src/test/webapp/unit/module/primary/landscape/LandscapeMiniMapComponent.spec.ts index c6e5afb7548..7e07d780e23 100644 --- a/src/test/webapp/unit/module/primary/landscape/LandscapeMiniMapComponent.spec.ts +++ b/src/test/webapp/unit/module/primary/landscape/LandscapeMiniMapComponent.spec.ts @@ -66,7 +66,7 @@ describe('MiniMap component', () => { await minimapViewer.trigger('mousemove'); await wrapper.vm.$nextTick(); - expect(landscapeContainer.scroll).toHaveBeenCalledTimes(0); + expect(landscapeContainer.scroll).not.toHaveBeenCalled(); }); it('should track the scroller position of the landscape container', async () => { From a33f47c66c884423fa00d5f1481712bdafa5efa5 Mon Sep 17 00:00:00 2001 From: Quentin Date: Sun, 26 Jan 2025 21:26:21 +0100 Subject: [PATCH 3/4] Tests: replace toEqual by toBe for string comparison --- .../app/admin/health/health.component.spec.ts.mustache | 4 ++-- .../modal/health-modal.component.spec.ts.mustache | 10 +++++----- .../config/application-config.service.spec.ts.mustache | 4 ++-- .../src/main/webapp/app/app.component.spec.ts.mustache | 2 +- .../webapp/app/login/login.component.spec.ts.mustache | 2 +- .../app/auth/http-auth.interceptor.spec.ts.mustache | 4 ++-- .../generator/client/common/i18n/i18n.spec.ts | 4 ++-- .../resources/projects/angular/app.component.spec.ts | 2 +- .../primary/landscape/LandscapeComponent.spec.ts | 4 ++-- .../primary/landscape/LandscapeConnector.spec.ts | 4 ++-- .../modules-patch/ModulesPatchComponent.spec.ts | 4 ++-- .../secondary/RestProjectFoldersRepository.spec.ts | 2 +- 12 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/main/resources/generator/client/angular/admin/src/main/webapp/app/admin/health/health.component.spec.ts.mustache b/src/main/resources/generator/client/angular/admin/src/main/webapp/app/admin/health/health.component.spec.ts.mustache index 1be0af988b3..581ec2cef07 100644 --- a/src/main/resources/generator/client/angular/admin/src/main/webapp/app/admin/health/health.component.spec.ts.mustache +++ b/src/main/resources/generator/client/angular/admin/src/main/webapp/app/admin/health/health.component.spec.ts.mustache @@ -73,13 +73,13 @@ describe('HealthComponent', () => { it('should get success badge class', () => { const upBadgeClass = comp.getBadgeClass('UP'); - expect(upBadgeClass).toEqual('bg-success'); + expect(upBadgeClass).toBe('bg-success'); }); it('should get danger badge class', () => { const downBadgeClass = comp.getBadgeClass('DOWN'); - expect(downBadgeClass).toEqual('bg-danger'); + expect(downBadgeClass).toBe('bg-danger'); }); }); }); diff --git a/src/main/resources/generator/client/angular/admin/src/main/webapp/app/admin/health/modal/health-modal.component.spec.ts.mustache b/src/main/resources/generator/client/angular/admin/src/main/webapp/app/admin/health/modal/health-modal.component.spec.ts.mustache index 571a2cc20a2..080c17fdb11 100644 --- a/src/main/resources/generator/client/angular/admin/src/main/webapp/app/admin/health/modal/health-modal.component.spec.ts.mustache +++ b/src/main/resources/generator/client/angular/admin/src/main/webapp/app/admin/health/modal/health-modal.component.spec.ts.mustache @@ -29,7 +29,7 @@ describe('HealthModalComponent', () => { const result = comp.readableValue({ name: 'jhipster' }); - expect(result).toEqual('{"name":"jhipster"}'); + expect(result).toBe('{"name":"jhipster"}'); }); it('should return string value', () => { @@ -40,7 +40,7 @@ describe('HealthModalComponent', () => { const result = comp.readableValue('jhipster'); - expect(result).toEqual('jhipster'); + expect(result).toBe('jhipster'); }); it('should return storage space in a human readable unit (GB)', () => { @@ -51,7 +51,7 @@ describe('HealthModalComponent', () => { const result = comp.readableValue(1073741825); - expect(result).toEqual('1.00 GB'); + expect(result).toBe('1.00 GB'); }); it('should return storage space in a human readable unit (MB)', () => { @@ -62,7 +62,7 @@ describe('HealthModalComponent', () => { const result = comp.readableValue(1073741824); - expect(result).toEqual('1024.00 MB'); + expect(result).toBe('1024.00 MB'); }); it('should return string value', () => { @@ -73,7 +73,7 @@ describe('HealthModalComponent', () => { const result = comp.readableValue(1234); - expect(result).toEqual('1234'); + expect(result).toBe('1234'); }); }); }); diff --git a/src/main/resources/generator/client/angular/admin/src/main/webapp/app/config/application-config.service.spec.ts.mustache b/src/main/resources/generator/client/angular/admin/src/main/webapp/app/config/application-config.service.spec.ts.mustache index 0fc3c1d89f3..c5dd6c35a1e 100644 --- a/src/main/resources/generator/client/angular/admin/src/main/webapp/app/config/application-config.service.spec.ts.mustache +++ b/src/main/resources/generator/client/angular/admin/src/main/webapp/app/config/application-config.service.spec.ts.mustache @@ -12,7 +12,7 @@ describe('ApplicationConfigService', () => { describe('without prefix', () => { it('should return correctly', () => { - expect(service.getEndpointFor('api')).toEqual('api'); + expect(service.getEndpointFor('api')).toBe('api'); }); }); @@ -22,7 +22,7 @@ describe('ApplicationConfigService', () => { }); it('should return correctly', () => { - expect(service.getEndpointFor('api')).toEqual('prefix/api'); + expect(service.getEndpointFor('api')).toBe('prefix/api'); }); }); }); diff --git a/src/main/resources/generator/client/angular/core/src/main/webapp/app/app.component.spec.ts.mustache b/src/main/resources/generator/client/angular/core/src/main/webapp/app/app.component.spec.ts.mustache index b8152351a94..de2b3140439 100644 --- a/src/main/resources/generator/client/angular/core/src/main/webapp/app/app.component.spec.ts.mustache +++ b/src/main/resources/generator/client/angular/core/src/main/webapp/app/app.component.spec.ts.mustache @@ -20,7 +20,7 @@ describe('App Component', () => { describe('ngOnInit', () => { it('should have appName', () => { - expect(comp.appName()).toEqual('{{baseName}}'); + expect(comp.appName()).toBe('{{baseName}}'); }); }); }); diff --git a/src/main/resources/generator/client/angular/security/jwt/src/main/webapp/app/login/login.component.spec.ts.mustache b/src/main/resources/generator/client/angular/security/jwt/src/main/webapp/app/login/login.component.spec.ts.mustache index c426e5db7d8..639a429a85e 100644 --- a/src/main/resources/generator/client/angular/security/jwt/src/main/webapp/app/login/login.component.spec.ts.mustache +++ b/src/main/resources/generator/client/angular/security/jwt/src/main/webapp/app/login/login.component.spec.ts.mustache @@ -92,7 +92,7 @@ describe('Login Component', () => { comp.login(); - expect(comp.errorMessage()).toEqual('Authentication failed'); + expect(comp.errorMessage()).toBe('Authentication failed'); }); }); diff --git a/src/main/resources/generator/client/angular/security/oauth2/src/main/webapp/app/auth/http-auth.interceptor.spec.ts.mustache b/src/main/resources/generator/client/angular/security/oauth2/src/main/webapp/app/auth/http-auth.interceptor.spec.ts.mustache index 3af799378c3..0f8cca7d839 100644 --- a/src/main/resources/generator/client/angular/security/oauth2/src/main/webapp/app/auth/http-auth.interceptor.spec.ts.mustache +++ b/src/main/resources/generator/client/angular/security/oauth2/src/main/webapp/app/auth/http-auth.interceptor.spec.ts.mustache @@ -40,7 +40,7 @@ describe('httpAuthInterceptor', () => { const req = httpTestingController.expectOne(originalRequest.url); expect(req.request.method).toEqual(HTTP_METHOD); expect(req.request.url).toEqual(URL); - expect(req.request.headers.get('ContentType')).toEqual('application/json'); + expect(req.request.headers.get('ContentType')).toBe('application/json'); expect(req.request.headers.get('Authorization')).toEqual(`Bearer ${TOKEN}`); }); @@ -51,7 +51,7 @@ describe('httpAuthInterceptor', () => { httpClient.request(originalRequest).subscribe(); const req = httpTestingController.expectOne(originalRequest.url); - expect(req.request.headers.get('ContentType')).toEqual('application/json'); + expect(req.request.headers.get('ContentType')).toBe('application/json'); expect(req.request.headers.get('Authorization')).toBeFalsy(); }); }); diff --git a/src/main/resources/generator/client/common/i18n/i18n.spec.ts b/src/main/resources/generator/client/common/i18n/i18n.spec.ts index 326c93a9648..f837218e0dc 100644 --- a/src/main/resources/generator/client/common/i18n/i18n.spec.ts +++ b/src/main/resources/generator/client/common/i18n/i18n.spec.ts @@ -3,11 +3,11 @@ import { mergeTranslations } from '@/Translations'; describe('i18n configuration', () => { it('loads en translation', () => { - expect(i18n.getResourceBundle('en', '')['home']['translationEnabled']).toEqual('Internationalization enabled'); + expect(i18n.getResourceBundle('en', '')['home']['translationEnabled']).toBe('Internationalization enabled'); }); it('loads fr translation', () => { - expect(i18n.getResourceBundle('fr', '')['home']['translationEnabled']).toEqual('Internationalisation activée'); + expect(i18n.getResourceBundle('fr', '')['home']['translationEnabled']).toBe('Internationalisation activée'); }); describe('mergeTranslations function', () => { diff --git a/src/test/resources/projects/angular/app.component.spec.ts b/src/test/resources/projects/angular/app.component.spec.ts index e5107cb2125..87c6b7b58f0 100644 --- a/src/test/resources/projects/angular/app.component.spec.ts +++ b/src/test/resources/projects/angular/app.component.spec.ts @@ -21,7 +21,7 @@ describe('App Component', () => { describe('ngOnInit', () => { it('should have appName', () => { - expect(comp.appName()).toEqual('test'); + expect(comp.appName()).toBe('test'); }); }); }); diff --git a/src/test/webapp/unit/module/primary/landscape/LandscapeComponent.spec.ts b/src/test/webapp/unit/module/primary/landscape/LandscapeComponent.spec.ts index 2b9bb13940f..8abed075bee 100644 --- a/src/test/webapp/unit/module/primary/landscape/LandscapeComponent.spec.ts +++ b/src/test/webapp/unit/module/primary/landscape/LandscapeComponent.spec.ts @@ -168,7 +168,7 @@ describe('Landscape', () => { return mount(LandscapeVue); } catch (e) { if (e instanceof Error) { - expect(e.message).toEqual('repositoryWithLandscapeError'); + expect(e.message).toBe('repositoryWithLandscapeError'); } expect(console.error).toHaveBeenCalled(); } @@ -196,7 +196,7 @@ describe('Landscape', () => { return mount(LandscapeVue); } catch (e) { if (e instanceof Error) { - expect(e.message).toEqual('repositoryWithProjectFoldersErrorww'); + expect(e.message).toBe('repositoryWithProjectFoldersErrorww'); } expect(console.error).toHaveBeenCalled(); } diff --git a/src/test/webapp/unit/module/primary/landscape/LandscapeConnector.spec.ts b/src/test/webapp/unit/module/primary/landscape/LandscapeConnector.spec.ts index f2fd36d16e7..ecc7201f2b4 100644 --- a/src/test/webapp/unit/module/primary/landscape/LandscapeConnector.spec.ts +++ b/src/test/webapp/unit/module/primary/landscape/LandscapeConnector.spec.ts @@ -25,7 +25,7 @@ describe('LandscapeConnector', () => { ]; const landscapeConnector: LandscapeConnector = new LandscapeConnector(positions, moduleSlug('moduleA'), moduleSlug('B')); //MoveTo 'startPoint', LineTo, CurveTo(3 points), LineTo, CurveTo(3 points), LineTo 'endPoint' - expect(landscapeConnector.path).toEqual('M 0 0 L 4 0 C 4 0 10 0 10 6 L 10 94 C 10 94 10 100 16 100 L 100 100'); + expect(landscapeConnector.path).toBe('M 0 0 L 4 0 C 4 0 10 0 10 6 L 10 94 C 10 94 10 100 16 100 L 100 100'); }); it('should generate curved path for top-right dependant', () => { @@ -49,7 +49,7 @@ describe('LandscapeConnector', () => { ]; const landscapeConnector: LandscapeConnector = new LandscapeConnector(positions, moduleSlug('moduleA'), moduleSlug('B')); //MoveTo 'startPoint', LineTo, CurveTo(3 points), LineTo, CurveTo(3 points), LineTo 'endPoint' - expect(landscapeConnector.path).toEqual('M 100 100 L 104 100 C 104 100 110 100 110 94 L 110 6 C 110 6 110 0 116 0 L 200 0'); + expect(landscapeConnector.path).toBe('M 100 100 L 104 100 C 104 100 110 100 110 94 L 110 6 C 110 6 110 0 116 0 L 200 0'); }); }); }); diff --git a/src/test/webapp/unit/module/primary/modules-patch/ModulesPatchComponent.spec.ts b/src/test/webapp/unit/module/primary/modules-patch/ModulesPatchComponent.spec.ts index a0649e18046..bcb7176b513 100644 --- a/src/test/webapp/unit/module/primary/modules-patch/ModulesPatchComponent.spec.ts +++ b/src/test/webapp/unit/module/primary/modules-patch/ModulesPatchComponent.spec.ts @@ -81,7 +81,7 @@ describe('Modules', () => { return mount(ModulesVue); } catch (e) { if (e instanceof Error) { - expect(e.message).toEqual('repositoryWithModulesError'); + expect(e.message).toBe('repositoryWithModulesError'); } expect(console.error).toHaveBeenCalled(); } @@ -104,7 +104,7 @@ describe('Modules', () => { return mount(ModulesVue); } catch (e) { if (e instanceof Error) { - expect(e.message).toEqual('repositoryWithProjectFoldersError'); + expect(e.message).toBe('repositoryWithProjectFoldersError'); } expect(console.error).toHaveBeenCalled(); } diff --git a/src/test/webapp/unit/module/secondary/RestProjectFoldersRepository.spec.ts b/src/test/webapp/unit/module/secondary/RestProjectFoldersRepository.spec.ts index cb7be083d2a..cef11b429ea 100644 --- a/src/test/webapp/unit/module/secondary/RestProjectFoldersRepository.spec.ts +++ b/src/test/webapp/unit/module/secondary/RestProjectFoldersRepository.spec.ts @@ -10,6 +10,6 @@ describe('Rest project folders repository', () => { const projectFolder = await repository.get(); - expect(projectFolder).toEqual('/tmp/jhlite/1234'); + expect(projectFolder).toBe('/tmp/jhlite/1234'); }); }); From 10fd1ee97c3942b817089061a344ea3bd9b1466c Mon Sep 17 00:00:00 2001 From: Quentin Date: Sun, 26 Jan 2025 21:48:15 +0100 Subject: [PATCH 4/4] Tests: replace toHaveBeenCalledOnce and toBeCalledWith by toHaveBeenCalledExactlyOnceWith --- .../primary/landscape/LandscapeComponent.spec.ts | 12 ++++-------- .../primary/landscape/LandscapeScroller.spec.ts | 9 +++------ .../infrastructure/secondary/MittAlertBus.spec.ts | 6 ++---- .../secondary/MittAlertListener.spec.ts | 6 ++---- .../infrastructure/secondary/ConsoleLogger.spec.ts | 3 +-- 5 files changed, 12 insertions(+), 24 deletions(-) diff --git a/src/test/webapp/unit/module/primary/landscape/LandscapeComponent.spec.ts b/src/test/webapp/unit/module/primary/landscape/LandscapeComponent.spec.ts index 8abed075bee..00de0c92de2 100644 --- a/src/test/webapp/unit/module/primary/landscape/LandscapeComponent.spec.ts +++ b/src/test/webapp/unit/module/primary/landscape/LandscapeComponent.spec.ts @@ -845,8 +845,7 @@ describe('Landscape', () => { const landscape = wrapper.find(wrappedElement('landscape-container')); await landscape.trigger('mousedown', mouseEvent); - expect(cursorUpdater.set).toHaveBeenCalledOnce(); - expect(cursorUpdater.set).toBeCalledWith('grabbing'); + expect(cursorUpdater.set).toHaveBeenCalledExactlyOnceWith('grabbing'); }); it('should prevent default clicking event when defined', async () => { @@ -909,8 +908,7 @@ describe('Landscape', () => { await landscape.trigger('mousedown', mouseEventStart); await landscape.trigger('mousemove', mouseEventGrabbed); - expect(landscapeScroller.scroll).toHaveBeenCalledOnce(); - expect(landscapeScroller.scroll).toBeCalledWith(expect.anything(), 20, 20); + expect(landscapeScroller.scroll).toHaveBeenCalledExactlyOnceWith(expect.anything(), 20, 20); }); it('should not scroll without starting grabbing', async () => { @@ -1277,8 +1275,7 @@ describe('Landscape', () => { expect(mockModuleRect).toHaveBeenCalled(); expect(mockContainerRect).toHaveBeenCalled(); - expect(landscapeScroller.scrollIntoView).toHaveBeenCalledOnce(); - expect(landscapeScroller.scrollIntoView).toHaveBeenCalledWith(prettierModule); + expect(landscapeScroller.scrollIntoView).toHaveBeenCalledExactlyOnceWith(prettierModule); }); it('should not scroll if the highlighted module is already visible', async () => { @@ -1321,8 +1318,7 @@ describe('Landscape', () => { await performSearch(searchInput, ''); - expect(landscapeScroller.scrollSmooth).toHaveBeenCalledOnce(); - expect(landscapeScroller.scrollSmooth).toHaveBeenCalledWith(landscapeContainer, 0, 0); + expect(landscapeScroller.scrollSmooth).toHaveBeenCalledExactlyOnceWith(landscapeContainer, 0, 0); }); const setupSearchTest = async () => { diff --git a/src/test/webapp/unit/module/primary/landscape/LandscapeScroller.spec.ts b/src/test/webapp/unit/module/primary/landscape/LandscapeScroller.spec.ts index a2a6dc3f41f..4401ad661c6 100644 --- a/src/test/webapp/unit/module/primary/landscape/LandscapeScroller.spec.ts +++ b/src/test/webapp/unit/module/primary/landscape/LandscapeScroller.spec.ts @@ -18,8 +18,7 @@ describe('LandscapeScroller', () => { landscapeScroller.scroll(element, 10, 10); - expect(element.scroll).toHaveBeenCalledOnce(); - expect(element.scroll).toBeCalledWith(10, 10); + expect(element.scroll).toHaveBeenCalledExactlyOnceWith(10, 10); }); it('should scroll smooth', () => { @@ -28,8 +27,7 @@ describe('LandscapeScroller', () => { landscapeScroller.scrollSmooth(element, 10, 10); - expect(element.scroll).toHaveBeenCalledOnce(); - expect(element.scroll).toBeCalledWith({ left: 10, top: 10, behavior: 'smooth' }); + expect(element.scroll).toHaveBeenCalledExactlyOnceWith({ left: 10, top: 10, behavior: 'smooth' }); }); it('should scroll into view', () => { @@ -38,7 +36,6 @@ describe('LandscapeScroller', () => { landscapeScroller.scrollIntoView(element); - expect(element.scrollIntoView).toHaveBeenCalledOnce(); - expect(element.scrollIntoView).toBeCalledWith({ behavior: 'smooth', block: 'center', inline: 'center' }); + expect(element.scrollIntoView).toHaveBeenCalledExactlyOnceWith({ behavior: 'smooth', block: 'center', inline: 'center' }); }); }); diff --git a/src/test/webapp/unit/shared/alert/infrastructure/secondary/MittAlertBus.spec.ts b/src/test/webapp/unit/shared/alert/infrastructure/secondary/MittAlertBus.spec.ts index 95de60e36be..3005094090f 100644 --- a/src/test/webapp/unit/shared/alert/infrastructure/secondary/MittAlertBus.spec.ts +++ b/src/test/webapp/unit/shared/alert/infrastructure/secondary/MittAlertBus.spec.ts @@ -10,8 +10,7 @@ describe('MittAlertBus', () => { mittAlertBus.success('A message'); - expect(emitterStub.emit).toHaveBeenCalledOnce(); - expect(emitterStub.emit).toBeCalledWith(AlertType.SUCCESS, 'A message'); + expect(emitterStub.emit).toHaveBeenCalledExactlyOnceWith(AlertType.SUCCESS, 'A message'); }); it('should emit error', () => { @@ -20,7 +19,6 @@ describe('MittAlertBus', () => { mittAlertBus.error('A message'); - expect(emitterStub.emit).toHaveBeenCalledOnce(); - expect(emitterStub.emit).toBeCalledWith(AlertType.ERROR, 'A message'); + expect(emitterStub.emit).toHaveBeenCalledExactlyOnceWith(AlertType.ERROR, 'A message'); }); }); diff --git a/src/test/webapp/unit/shared/alert/infrastructure/secondary/MittAlertListener.spec.ts b/src/test/webapp/unit/shared/alert/infrastructure/secondary/MittAlertListener.spec.ts index 175958507c2..d116466ee7d 100644 --- a/src/test/webapp/unit/shared/alert/infrastructure/secondary/MittAlertListener.spec.ts +++ b/src/test/webapp/unit/shared/alert/infrastructure/secondary/MittAlertListener.spec.ts @@ -12,8 +12,7 @@ describe('MittAlertListener', () => { emitter.emit(AlertType.SUCCESS, 'A message'); - expect(spyAlerted).toHaveBeenCalledOnce(); - expect(spyAlerted).toBeCalledWith('A message'); + expect(spyAlerted).toHaveBeenCalledExactlyOnceWith('A message'); }); it('should unsubscribe success', () => { @@ -39,8 +38,7 @@ describe('MittAlertListener', () => { emitter.emit(AlertType.ERROR, 'A message'); - expect(spyAlerted).toHaveBeenCalledOnce(); - expect(spyAlerted).toBeCalledWith('A message'); + expect(spyAlerted).toHaveBeenCalledExactlyOnceWith('A message'); }); it('should unsubscribe error', () => { diff --git a/src/test/webapp/unit/shared/logger/infrastructure/secondary/ConsoleLogger.spec.ts b/src/test/webapp/unit/shared/logger/infrastructure/secondary/ConsoleLogger.spec.ts index 03340e50f16..6cb5c9b3df2 100644 --- a/src/test/webapp/unit/shared/logger/infrastructure/secondary/ConsoleLogger.spec.ts +++ b/src/test/webapp/unit/shared/logger/infrastructure/secondary/ConsoleLogger.spec.ts @@ -11,7 +11,6 @@ describe('ConsoleLogger', () => { consoleLogger.error('An error occurs', error); - expect(logger.error).toHaveBeenCalledOnce(); - expect(logger.error).toBeCalledWith('An error occurs\n', error); + expect(logger.error).toHaveBeenCalledExactlyOnceWith('An error occurs\n', error); }); });