diff --git a/core-web/libs/data-access/jest.config.ts b/core-web/libs/data-access/jest.config.ts index e560babc229f..6f569852e2ee 100644 --- a/core-web/libs/data-access/jest.config.ts +++ b/core-web/libs/data-access/jest.config.ts @@ -4,7 +4,6 @@ export default { preset: '../../jest.preset.js', setupFilesAfterEnv: ['/src/test-setup.ts'], globals: {}, - coverageDirectory: '../../coverage/libs/data-access', coverageReporters: ['html', ['lcovonly', { file: 'TEST-template-builder.lcov' }]], reporters: [ 'default', diff --git a/core-web/libs/ui/jest.config.ts b/core-web/libs/ui/jest.config.ts new file mode 100644 index 000000000000..09542c893d65 --- /dev/null +++ b/core-web/libs/ui/jest.config.ts @@ -0,0 +1,31 @@ +export default { + displayName: 'ui', + preset: '../../jest.preset.js', + setupFilesAfterEnv: ['/src/test-setup.ts'], + globals: {}, + coverageReporters: [['lcovonly', { file: 'TEST-block-editor.lcov' }]], + reporters: [ + 'default', + ['github-actions', { silent: false }], + [ + 'jest-junit', + { outputDirectory: '../target/core-web-reports', outputName: 'TEST-block-editor.xml' } + ] + ], + snapshotSerializers: [ + 'jest-preset-angular/build/serializers/no-ng-attributes', + 'jest-preset-angular/build/serializers/ng-snapshot', + 'jest-preset-angular/build/serializers/html-comment' + ], + transform: { + '^.+.(ts|mjs|js|html)$': [ + 'jest-preset-angular', + { + stringifyContentPathRegex: '\\.(html|svg)$', + + tsconfig: '/tsconfig.spec.json' + } + ] + }, + transformIgnorePatterns: ['node_modules/(?!.*.mjs$)'] +}; diff --git a/core-web/libs/ui/karma.conf.js b/core-web/libs/ui/karma.conf.js deleted file mode 100644 index 67de7f0f9203..000000000000 --- a/core-web/libs/ui/karma.conf.js +++ /dev/null @@ -1,16 +0,0 @@ -// Karma configuration file, see link for more information -// https://karma-runner.github.io/1.0/config/configuration-file.html - -const { join } = require('path'); -const getBaseKarmaConfig = require('../../karma.conf'); - -module.exports = function (config) { - const baseConfig = getBaseKarmaConfig(); - config.set({ - ...baseConfig, - coverageIstanbulReporter: { - ...baseConfig.coverageIstanbulReporter, - dir: join(__dirname, '../../coverage/libs/ui') - } - }); -}; diff --git a/core-web/libs/ui/project.json b/core-web/libs/ui/project.json index a478308f23ca..794c09527380 100644 --- a/core-web/libs/ui/project.json +++ b/core-web/libs/ui/project.json @@ -10,15 +10,11 @@ "outputs": ["{options.outputFile}"] }, "test": { - "executor": "@angular-devkit/build-angular:karma", + "executor": "@nx/jest:jest", + "outputs": ["{workspaceRoot}/coverage/{projectName}"], "options": { - "main": "libs/ui/src/test.ts", - "tsConfig": "libs/ui/tsconfig.spec.json", - "karmaConfig": "libs/ui/karma.conf.js", - "styles": ["libs/dotcms-scss/angular/styles.scss"], - "stylePreprocessorOptions": { - "includePaths": ["libs/dotcms-scss/angular/"] - } + "jestConfig": "libs/ui/jest.config.ts", + "passWithNoTests": false } } }, diff --git a/core-web/libs/ui/src/lib/components/dot-action-menu-button/dot-action-menu-button.component.spec.ts b/core-web/libs/ui/src/lib/components/dot-action-menu-button/dot-action-menu-button.component.spec.ts index 8a0409d960bb..d0826f2655bb 100644 --- a/core-web/libs/ui/src/lib/components/dot-action-menu-button/dot-action-menu-button.component.spec.ts +++ b/core-web/libs/ui/src/lib/components/dot-action-menu-button/dot-action-menu-button.component.spec.ts @@ -1,6 +1,5 @@ -import { DebugElement } from '@angular/core'; -import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { By } from '@angular/platform-browser'; +import { Spectator, byTestId, createComponentFactory } from '@ngneat/spectator/jest'; + import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { ButtonModule } from 'primeng/button'; @@ -11,24 +10,17 @@ import { DotActionMenuButtonComponent, DotMenuComponent } from '@dotcms/ui'; import { dotcmsContentTypeBasicMock } from '@dotcms/utils-testing'; describe('ActionMenuButtonComponent', () => { - let comp: DotActionMenuButtonComponent; - let fixture: ComponentFixture; - let de: DebugElement; - - beforeEach(() => { - TestBed.configureTestingModule({ - imports: [ - ButtonModule, - TooltipModule, - DotMenuComponent, - BrowserAnimationsModule, - DotActionMenuButtonComponent - ] - }).compileComponents(); + let spectator: Spectator; - fixture = TestBed.createComponent(DotActionMenuButtonComponent); - comp = fixture.componentInstance; - de = fixture.debugElement; + const createComponent = createComponentFactory({ + component: DotActionMenuButtonComponent, + imports: [ + ButtonModule, + TooltipModule, + DotMenuComponent, + BrowserAnimationsModule, + DotActionMenuButtonComponent + ] }); it('should display a menu button with multiple actions if actions are more than 1', () => { @@ -54,12 +46,16 @@ describe('ActionMenuButtonComponent', () => { } ]; - comp.actions = fakeActions; - fixture.detectChanges(); + spectator = createComponent({ + props: { + actions: fakeActions + } + }); + spectator.detectChanges(); - const button = de.query(By.css('.dot-menu__button')); - const buttonTooltip = de.query(By.css('[data-testid="dot-action-tooltip-button"]')); - const menu = de.query(By.css('dot-menu')); + const button = spectator.query('.dot-menu__button'); + const buttonTooltip = spectator.query(byTestId('dot-action-tooltip-button')); + const menu = spectator.query('dot-menu'); expect(buttonTooltip).toBeNull(); expect(button).toBeDefined(); @@ -79,11 +75,15 @@ describe('ActionMenuButtonComponent', () => { } ]; - comp.actions = fakeActions; - fixture.detectChanges(); + spectator = createComponent({ + props: { + actions: fakeActions + } + }); + spectator.detectChanges(); - const actionButtonTooltip = de.query(By.css('[data-testid="dot-action-tooltip-button"]')); - const actionButtonMenu = de.query(By.css('dot-menu')); + const actionButtonTooltip = spectator.query(byTestId('dot-action-tooltip-button')); + const actionButtonMenu = spectator.query('dot-menu'); expect(actionButtonTooltip).not.toBeNull(); expect(actionButtonMenu).toBeNull(); @@ -114,15 +114,18 @@ describe('ActionMenuButtonComponent', () => { owner: '123', system: false }; + spectator = createComponent({ + props: { + actions: fakeActions, + item: mockContentType + } + }); + spectator.detectChanges(); - comp.actions = fakeActions; - comp.item = mockContentType; - fixture.detectChanges(); - - spyOn(fakeActions[0].menuItem, 'command'); + jest.spyOn(fakeActions[0].menuItem, 'command'); - const actionButtonTooltip = de.query(By.css('[data-testid="dot-action-tooltip-button"]')); - actionButtonTooltip.nativeElement.click(); + const actionButtonTooltip = spectator.query(byTestId('dot-action-tooltip-button')); + spectator.click(actionButtonTooltip); expect(fakeActions[0].menuItem.command).toHaveBeenCalledTimes(1); expect(fakeActions[0].menuItem.command).toHaveBeenCalledWith(mockContentType); @@ -162,10 +165,14 @@ describe('ActionMenuButtonComponent', () => { } ]; - comp.actions = fakeActions; - comp.ngOnInit(); + spectator = createComponent({ + props: { + actions: fakeActions + } + }); + spectator.detectChanges(); - expect(comp.filteredActions.length).toEqual(1); + expect(spectator.component.filteredActions.length).toEqual(1); }); it('should render button with submenu', () => { @@ -203,20 +210,25 @@ describe('ActionMenuButtonComponent', () => { system: false }; - comp.actions = fakeActions; - comp.item = mockContentType; - fixture.detectChanges(); + spectator = createComponent({ + props: { + actions: fakeActions, + item: mockContentType + } + }); + spectator.detectChanges(); + + const actionButtonTooltip = spectator.query(byTestId('dot-action-tooltip-button')); + const dotMenu = spectator.query('dot-menu'); + const button = spectator.query('button'); - expect(de.query(By.css('[data-testid="dot-action-tooltip-button"]')) === null).toEqual( - true, - 'tooltip button hide' - ); - expect(de.query(By.css('dot-menu')) === null).toEqual(false, 'menu options show'); - expect(de.query(By.css('button')) === null).toEqual(false, 'button to show/hide menu show'); + expect(actionButtonTooltip).toBeNull(); + expect(dotMenu).not.toBeNull(); + expect(button).not.toBeNull(); }); it('should call menu option actions with item passed', () => { - const fakeCommand = jasmine.createSpy('fakeCommand'); + const fakeCommand = jest.fn(); const fakeActions: DotActionMenuItem[] = [ { @@ -251,19 +263,22 @@ describe('ActionMenuButtonComponent', () => { owner: '123', system: false }; - comp.actions = fakeActions; - comp.item = mockContentType; - fixture.detectChanges(); - const actionButtonMenu = de.query(By.css('[data-testid="dot-menu-button"]')); - actionButtonMenu.triggerEventHandler('click', { + spectator = createComponent({ + props: { + actions: fakeActions, + item: mockContentType + } + }); + spectator.detectChanges(); + spectator.triggerEventHandler(`[data-testid="dot-menu-button"]`, 'click', { stopPropagation: () => { // } }); - fixture.detectChanges(); + spectator.detectChanges(); - const menuItemsLink = de.queryAll(By.css('.p-menuitem-link')); - menuItemsLink[1].nativeElement.click(); + const menuItemsLink = spectator.queryAll('.p-menuitem-link'); + spectator.click(menuItemsLink[1]); expect(fakeCommand).toHaveBeenCalledTimes(1); expect(fakeCommand).toHaveBeenCalledWith(mockContentType); diff --git a/core-web/libs/ui/src/lib/components/dot-ai-image-prompt/ai-image-prompt.component.spec.ts b/core-web/libs/ui/src/lib/components/dot-ai-image-prompt/ai-image-prompt.component.spec.ts index d75dc9ffe936..e586e9b27324 100644 --- a/core-web/libs/ui/src/lib/components/dot-ai-image-prompt/ai-image-prompt.component.spec.ts +++ b/core-web/libs/ui/src/lib/components/dot-ai-image-prompt/ai-image-prompt.component.spec.ts @@ -1,4 +1,4 @@ -import { byTestId, createComponentFactory, mockProvider, Spectator } from '@ngneat/spectator'; +import { byTestId, createComponentFactory, mockProvider, Spectator } from '@ngneat/spectator/jest'; import { of } from 'rxjs'; import { HttpClientTestingModule } from '@angular/common/http/testing'; @@ -40,11 +40,11 @@ describe('DotAIImagePromptComponent', () => { galleryActiveIndex: 0, orientation: DotAIImageOrientation.VERTICAL }), - generateImage: jasmine.createSpy('generateImage'), - hideDialog: jasmine.createSpy('hideDialog'), - patchState: jasmine.createSpy('patchState'), - cleanError: jasmine.createSpy('cleanError'), - setSelectedImage: jasmine.createSpy('setSelectedImage') + generateImage: jest.fn(), + hideDialog: jest.fn(), + patchState: jest.fn(), + cleanError: jest.fn(), + setSelectedImage: jest.fn() } }, mockProvider(ConfirmationService) @@ -92,7 +92,7 @@ describe('DotAIImagePromptComponent', () => { it('should call confirm dialog when try to close dialog', fakeAsync(() => { const closeBtn = spectator.query(byTestId('close-btn')); - const spyCloseDialog = spyOn(spectator.component, 'closeDialog'); + const spyCloseDialog = jest.spyOn(spectator.component, 'closeDialog'); spectator.click(closeBtn); spectator.tick(); diff --git a/core-web/libs/ui/src/lib/components/dot-ai-image-prompt/components/ai-image-prompt-form/ai-image-prompt-form.component.spec.ts b/core-web/libs/ui/src/lib/components/dot-ai-image-prompt/components/ai-image-prompt-form/ai-image-prompt-form.component.spec.ts index ca55d14f4a72..21ca2d8c9298 100644 --- a/core-web/libs/ui/src/lib/components/dot-ai-image-prompt/components/ai-image-prompt-form/ai-image-prompt-form.component.spec.ts +++ b/core-web/libs/ui/src/lib/components/dot-ai-image-prompt/components/ai-image-prompt-form/ai-image-prompt-form.component.spec.ts @@ -45,7 +45,7 @@ describe('DotAiImagePromptFormComponent', () => { }); it('should emit value when form value change', () => { - const emitSpy = spyOn(spectator.component.valueChange, 'emit'); + const emitSpy = jest.spyOn(spectator.component.valueChange, 'emit'); spectator.component.form.setValue(formValue); spectator.detectChanges(); @@ -85,7 +85,7 @@ describe('DotAiImagePromptFormComponent', () => { }); it('should emit generate when the form is submitted', () => { - const valueSpy = spyOn(spectator.component.generate, 'emit'); + const valueSpy = jest.spyOn(spectator.component.generate, 'emit'); spectator.setInput({ isLoading: false }); spectator.component.form.setValue(formValue); spectator.detectChanges(); diff --git a/core-web/libs/ui/src/lib/components/dot-ai-image-prompt/components/ai-image-prompt-gallery/ai-image-prompt-gallery.component.spec.ts b/core-web/libs/ui/src/lib/components/dot-ai-image-prompt/components/ai-image-prompt-gallery/ai-image-prompt-gallery.component.spec.ts index bdeaf53b5d3c..35e6b3712528 100644 --- a/core-web/libs/ui/src/lib/components/dot-ai-image-prompt/components/ai-image-prompt-gallery/ai-image-prompt-gallery.component.spec.ts +++ b/core-web/libs/ui/src/lib/components/dot-ai-image-prompt/components/ai-image-prompt-gallery/ai-image-prompt-gallery.component.spec.ts @@ -74,7 +74,7 @@ describe('DotAiImagePromptGalleryComponent', () => { }); it('should emit activeIndexChange event when galleria active index changes', () => { - const emitterSpy = spyOn(spectator.component.activeIndexChange, 'emit'); + const emitterSpy = jest.spyOn(spectator.component.activeIndexChange, 'emit'); spectator.setInput({ isLoading: false, @@ -88,7 +88,7 @@ describe('DotAiImagePromptGalleryComponent', () => { }); it('should emit regenerate event when regenerate button is clicked', () => { - const emitterSpy = spyOn(spectator.component.regenerate, 'emit'); + const emitterSpy = jest.spyOn(spectator.component.regenerate, 'emit'); spectator.setInput({ isLoading: false, diff --git a/core-web/libs/ui/src/lib/components/dot-asset-search/components/dot-asset-card-list/dot-asset-card-list.component.spec.ts b/core-web/libs/ui/src/lib/components/dot-asset-search/components/dot-asset-card-list/dot-asset-card-list.component.spec.ts index 329d9eaa9697..ad74597a5471 100644 --- a/core-web/libs/ui/src/lib/components/dot-asset-search/components/dot-asset-card-list/dot-asset-card-list.component.spec.ts +++ b/core-web/libs/ui/src/lib/components/dot-asset-search/components/dot-asset-card-list/dot-asset-card-list.component.spec.ts @@ -1,4 +1,4 @@ -import { createComponentFactory, Spectator } from '@ngneat/spectator'; +import { createComponentFactory, Spectator } from '@ngneat/spectator/jest'; import { CommonModule } from '@angular/common'; diff --git a/core-web/libs/ui/src/lib/components/dot-asset-search/components/dot-asset-card-skeleton/dot-asset-card-skeleton.component.spec.ts b/core-web/libs/ui/src/lib/components/dot-asset-search/components/dot-asset-card-skeleton/dot-asset-card-skeleton.component.spec.ts index 126460fa44c2..f4078e5282a8 100644 --- a/core-web/libs/ui/src/lib/components/dot-asset-search/components/dot-asset-card-skeleton/dot-asset-card-skeleton.component.spec.ts +++ b/core-web/libs/ui/src/lib/components/dot-asset-search/components/dot-asset-card-skeleton/dot-asset-card-skeleton.component.spec.ts @@ -1,4 +1,4 @@ -import { createComponentFactory, Spectator } from '@ngneat/spectator'; +import { createComponentFactory, Spectator } from '@ngneat/spectator/jest'; import { CardModule } from 'primeng/card'; import { Skeleton, SkeletonModule } from 'primeng/skeleton'; diff --git a/core-web/libs/ui/src/lib/components/dot-asset-search/components/dot-asset-card/dot-asset-card.component.spec.ts b/core-web/libs/ui/src/lib/components/dot-asset-search/components/dot-asset-card/dot-asset-card.component.spec.ts index 55b2cd24ddd9..a6bda1fed878 100644 --- a/core-web/libs/ui/src/lib/components/dot-asset-search/components/dot-asset-card/dot-asset-card.component.spec.ts +++ b/core-web/libs/ui/src/lib/components/dot-asset-search/components/dot-asset-card/dot-asset-card.component.spec.ts @@ -1,4 +1,4 @@ -import { createComponentFactory, Spectator } from '@ngneat/spectator'; +import { createComponentFactory, Spectator } from '@ngneat/spectator/jest'; import { Card, CardModule } from 'primeng/card'; diff --git a/core-web/libs/ui/src/lib/components/dot-asset-search/components/dot-asset-search-dialog/dot-asset-search-dialog.component.spec.ts b/core-web/libs/ui/src/lib/components/dot-asset-search/components/dot-asset-search-dialog/dot-asset-search-dialog.component.spec.ts index 9fef576437e6..196e705feb10 100644 --- a/core-web/libs/ui/src/lib/components/dot-asset-search/components/dot-asset-search-dialog/dot-asset-search-dialog.component.spec.ts +++ b/core-web/libs/ui/src/lib/components/dot-asset-search/components/dot-asset-search-dialog/dot-asset-search-dialog.component.spec.ts @@ -1,4 +1,4 @@ -import { createComponentFactory, Spectator } from '@ngneat/spectator'; +import { createComponentFactory, Spectator } from '@ngneat/spectator/jest'; import { MockComponent } from 'ng-mocks'; import { DynamicDialogConfig, DynamicDialogRef } from 'primeng/dynamicdialog'; diff --git a/core-web/libs/ui/src/lib/components/dot-asset-search/dot-asset-search.component.spec.ts b/core-web/libs/ui/src/lib/components/dot-asset-search/dot-asset-search.component.spec.ts index 6b5a44f011da..50602ca1fce5 100644 --- a/core-web/libs/ui/src/lib/components/dot-asset-search/dot-asset-search.component.spec.ts +++ b/core-web/libs/ui/src/lib/components/dot-asset-search/dot-asset-search.component.spec.ts @@ -1,4 +1,4 @@ -import { byTestId, createComponentFactory, Spectator } from '@ngneat/spectator'; +import { byTestId, createComponentFactory, Spectator } from '@ngneat/spectator/jest'; import { of } from 'rxjs'; import { HttpClientTestingModule } from '@angular/common/http/testing'; diff --git a/core-web/libs/ui/src/lib/components/dot-asset-search/store/dot-asset-search.store.spec.ts b/core-web/libs/ui/src/lib/components/dot-asset-search/store/dot-asset-search.store.spec.ts index e9a055fc3f82..49a2f2c1edae 100644 --- a/core-web/libs/ui/src/lib/components/dot-asset-search/store/dot-asset-search.store.spec.ts +++ b/core-web/libs/ui/src/lib/components/dot-asset-search/store/dot-asset-search.store.spec.ts @@ -1,4 +1,4 @@ -import { SpectatorService, createServiceFactory } from '@ngneat/spectator'; +import { SpectatorService, createServiceFactory } from '@ngneat/spectator/jest'; import { of } from 'rxjs'; import { diff --git a/core-web/libs/ui/src/lib/components/dot-drop-zone/directive/dot-drop-zone-value-accesor/dot-drop-zone-value-accessor.directive.spec.ts b/core-web/libs/ui/src/lib/components/dot-drop-zone/directive/dot-drop-zone-value-accesor/dot-drop-zone-value-accessor.directive.spec.ts index 1da733f053e1..372d288e12da 100644 --- a/core-web/libs/ui/src/lib/components/dot-drop-zone/directive/dot-drop-zone-value-accesor/dot-drop-zone-value-accessor.directive.spec.ts +++ b/core-web/libs/ui/src/lib/components/dot-drop-zone/directive/dot-drop-zone-value-accesor/dot-drop-zone-value-accessor.directive.spec.ts @@ -1,4 +1,4 @@ -import { createDirectiveFactory, SpectatorDirective } from '@ngneat/spectator'; +import { createDirectiveFactory, SpectatorDirective } from '@ngneat/spectator/jest'; import { MockComponent } from 'ng-mocks'; import { forwardRef } from '@angular/core'; diff --git a/core-web/libs/ui/src/lib/components/dot-drop-zone/dot-drop-zone.component.spec.ts b/core-web/libs/ui/src/lib/components/dot-drop-zone/dot-drop-zone.component.spec.ts index f23656c5fad3..aa1c30cb461e 100644 --- a/core-web/libs/ui/src/lib/components/dot-drop-zone/dot-drop-zone.component.spec.ts +++ b/core-web/libs/ui/src/lib/components/dot-drop-zone/dot-drop-zone.component.spec.ts @@ -1,4 +1,4 @@ -import { SpectatorHost, createHostFactory } from '@ngneat/spectator'; +import { SpectatorHost, createHostFactory } from '@ngneat/spectator/jest'; import { CommonModule } from '@angular/common'; diff --git a/core-web/libs/ui/src/lib/components/dot-empty-container/dot-empty-container.component.spec.ts b/core-web/libs/ui/src/lib/components/dot-empty-container/dot-empty-container.component.spec.ts index 3946b52c5e2b..c6565edb1f48 100644 --- a/core-web/libs/ui/src/lib/components/dot-empty-container/dot-empty-container.component.spec.ts +++ b/core-web/libs/ui/src/lib/components/dot-empty-container/dot-empty-container.component.spec.ts @@ -1,5 +1,4 @@ -import { createComponentFactory, mockProvider, Spectator } from '@ngneat/spectator'; -import { byTestId } from '@ngneat/spectator/jest'; +import { createComponentFactory, mockProvider, Spectator, byTestId } from '@ngneat/spectator/jest'; import { DotMessageService } from '@dotcms/data-access'; import { DotEmptyContainerComponent, PrincipalConfiguration } from '@dotcms/ui'; diff --git a/core-web/libs/ui/src/lib/components/dot-field-validation-message/dot-field-validation-message.component.spec.ts b/core-web/libs/ui/src/lib/components/dot-field-validation-message/dot-field-validation-message.component.spec.ts index c9559a5caa56..f1bdde71c19c 100644 --- a/core-web/libs/ui/src/lib/components/dot-field-validation-message/dot-field-validation-message.component.spec.ts +++ b/core-web/libs/ui/src/lib/components/dot-field-validation-message/dot-field-validation-message.component.spec.ts @@ -1,7 +1,6 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ -import { createHostFactory, SpectatorHost } from '@ngneat/spectator'; -import { byTestId } from '@ngneat/spectator/jest'; +import { createHostFactory, SpectatorHost, byTestId } from '@ngneat/spectator/jest'; import { Component } from '@angular/core'; import { ReactiveFormsModule, UntypedFormControl, Validators } from '@angular/forms'; diff --git a/core-web/libs/ui/src/lib/components/dot-key-value-ng/dot-key-value-ng.component.spec.ts b/core-web/libs/ui/src/lib/components/dot-key-value-ng/dot-key-value-ng.component.spec.ts index bb78fe7387b5..59a6b80edc3a 100644 --- a/core-web/libs/ui/src/lib/components/dot-key-value-ng/dot-key-value-ng.component.spec.ts +++ b/core-web/libs/ui/src/lib/components/dot-key-value-ng/dot-key-value-ng.component.spec.ts @@ -1,4 +1,4 @@ -import { Spectator, createComponentFactory } from '@ngneat/spectator'; +import { Spectator, createComponentFactory } from '@ngneat/spectator/jest'; import { MockProvider } from 'ng-mocks'; import { Table, TableModule } from 'primeng/table'; @@ -88,7 +88,7 @@ describe('DotKeyValueComponent', () => { it('should call `event.stopPropagation()` when keydown.enter event is triggered', () => { const event = new KeyboardEvent('keydown', { bubbles: true, key: 'Enter' }); - const stopPropagationSpy = spyOn(event, 'stopPropagation'); + const stopPropagationSpy = jest.spyOn(event, 'stopPropagation'); const table = spectator.query('p-table'); // Use Table directly spectator.detectChanges(); @@ -98,8 +98,8 @@ describe('DotKeyValueComponent', () => { }); it('should update an existing variable', () => { - const spyUpdate = spyOn(spectator.component.update, 'emit'); - const spyUpdatedList = spyOn(spectator.component.updatedList, 'emit'); + const spyUpdate = jest.spyOn(spectator.component.update, 'emit'); + const spyUpdatedList = jest.spyOn(spectator.component.updatedList, 'emit'); spectator.detectChanges(); @@ -118,8 +118,8 @@ describe('DotKeyValueComponent', () => { }); it('should save a new variable', () => { - const spySave = spyOn(spectator.component.save, 'emit'); - const spyUpdatedList = spyOn(spectator.component.updatedList, 'emit'); + const spySave = jest.spyOn(spectator.component.save, 'emit'); + const spyUpdatedList = jest.spyOn(spectator.component.updatedList, 'emit'); const newVariable = { key: 'newKey', value: 'newValue', @@ -136,8 +136,8 @@ describe('DotKeyValueComponent', () => { }); it('should delete a variable from the list', () => { - const spyDelete = spyOn(spectator.component.delete, 'emit'); - const spyUpdatedList = spyOn(spectator.component.updatedList, 'emit'); + const spyDelete = jest.spyOn(spectator.component.delete, 'emit'); + const spyUpdatedList = jest.spyOn(spectator.component.updatedList, 'emit'); spectator.detectChanges(); @@ -162,8 +162,8 @@ describe('DotKeyValueComponent', () => { }); it('should save a hidden variable', () => { - const spysave = spyOn(spectator.component.save, 'emit'); - const spyUpdatedList = spyOn(spectator.component.updatedList, 'emit'); + const spysave = jest.spyOn(spectator.component.save, 'emit'); + const spyUpdatedList = jest.spyOn(spectator.component.updatedList, 'emit'); const newVariable = { key: 'newKey', @@ -181,8 +181,8 @@ describe('DotKeyValueComponent', () => { }); it('should update an existing variable', () => { - const spyupdate = spyOn(spectator.component.update, 'emit'); - const spyUpdatedList = spyOn(spectator.component.updatedList, 'emit'); + const spyupdate = jest.spyOn(spectator.component.update, 'emit'); + const spyUpdatedList = jest.spyOn(spectator.component.updatedList, 'emit'); spectator.detectChanges(); diff --git a/core-web/libs/ui/src/lib/components/dot-key-value-ng/dot-key-value-table-input-row/dot-key-value-table-input-row.component.spec.ts b/core-web/libs/ui/src/lib/components/dot-key-value-ng/dot-key-value-table-input-row/dot-key-value-table-input-row.component.spec.ts index 1b7b748689af..39b30bce1fc0 100644 --- a/core-web/libs/ui/src/lib/components/dot-key-value-ng/dot-key-value-table-input-row/dot-key-value-table-input-row.component.spec.ts +++ b/core-web/libs/ui/src/lib/components/dot-key-value-ng/dot-key-value-table-input-row/dot-key-value-table-input-row.component.spec.ts @@ -1,4 +1,4 @@ -import { byTestId, createHostFactory, SpectatorHost } from '@ngneat/spectator'; +import { byTestId, createHostFactory, SpectatorHost } from '@ngneat/spectator/jest'; import { MockProvider } from 'ng-mocks'; import { fakeAsync, tick } from '@angular/core/testing'; diff --git a/core-web/libs/ui/src/lib/components/dot-key-value-ng/dot-key-value-table-row/dot-key-value-table-row.component.spec.ts b/core-web/libs/ui/src/lib/components/dot-key-value-ng/dot-key-value-table-row/dot-key-value-table-row.component.spec.ts index be814ede5ee0..5f425bfff116 100644 --- a/core-web/libs/ui/src/lib/components/dot-key-value-ng/dot-key-value-table-row/dot-key-value-table-row.component.spec.ts +++ b/core-web/libs/ui/src/lib/components/dot-key-value-ng/dot-key-value-table-row/dot-key-value-table-row.component.spec.ts @@ -1,4 +1,4 @@ -import { Spectator, byTestId, createComponentFactory } from '@ngneat/spectator'; +import { Spectator, byTestId, createComponentFactory } from '@ngneat/spectator/jest'; import { CommonModule } from '@angular/common'; import { Component, Input, ViewChild } from '@angular/core'; diff --git a/core-web/libs/ui/src/lib/components/dot-menu/dot-menu.component.spec.ts b/core-web/libs/ui/src/lib/components/dot-menu/dot-menu.component.spec.ts index f56f6fd4fbaf..1f9ca9c0c375 100644 --- a/core-web/libs/ui/src/lib/components/dot-menu/dot-menu.component.spec.ts +++ b/core-web/libs/ui/src/lib/components/dot-menu/dot-menu.component.spec.ts @@ -56,9 +56,9 @@ describe('DotMenuComponent', () => { fixture.detectChanges(); button = fixture.debugElement.query(By.css('[data-testid="dot-menu-button"]')); - expect( - (button.componentInstance.styleClass as string).includes('p-button-text') - ).toBeTrue(); + expect((button.componentInstance.styleClass as string).includes('p-button-text')).toBe( + true + ); }); it('should pass menu items to the Menu', () => { diff --git a/core-web/libs/ui/src/lib/components/dot-sidebar-header/dot-sidebar-header.component.spec.ts b/core-web/libs/ui/src/lib/components/dot-sidebar-header/dot-sidebar-header.component.spec.ts index 0c77ce1c0a47..5c40c3ada205 100644 --- a/core-web/libs/ui/src/lib/components/dot-sidebar-header/dot-sidebar-header.component.spec.ts +++ b/core-web/libs/ui/src/lib/components/dot-sidebar-header/dot-sidebar-header.component.spec.ts @@ -1,4 +1,4 @@ -import { byTestId, createComponentFactory, Spectator } from '@ngneat/spectator'; +import { byTestId, createComponentFactory, Spectator } from '@ngneat/spectator/jest'; import { Sidebar } from 'primeng/sidebar'; diff --git a/core-web/libs/ui/src/lib/components/dot-temp-file-thumbnail/dot-temp-file-thumbnail.component.spec.ts b/core-web/libs/ui/src/lib/components/dot-temp-file-thumbnail/dot-temp-file-thumbnail.component.spec.ts index 8dabb6082b81..cdd2ba47c20f 100644 --- a/core-web/libs/ui/src/lib/components/dot-temp-file-thumbnail/dot-temp-file-thumbnail.component.spec.ts +++ b/core-web/libs/ui/src/lib/components/dot-temp-file-thumbnail/dot-temp-file-thumbnail.component.spec.ts @@ -1,4 +1,4 @@ -import { Spectator, byTestId, createComponentFactory } from '@ngneat/spectator'; +import { Spectator, byTestId, createComponentFactory } from '@ngneat/spectator/jest'; import { DotCMSTempFile } from '@dotcms/dotcms-models'; diff --git a/core-web/libs/ui/src/lib/components/dot-workflow-actions/dot-workflow-actions.component.spec.ts b/core-web/libs/ui/src/lib/components/dot-workflow-actions/dot-workflow-actions.component.spec.ts index 1bdb1611e57e..1361f01e43ce 100644 --- a/core-web/libs/ui/src/lib/components/dot-workflow-actions/dot-workflow-actions.component.spec.ts +++ b/core-web/libs/ui/src/lib/components/dot-workflow-actions/dot-workflow-actions.component.spec.ts @@ -1,4 +1,4 @@ -import { createComponentFactory, Spectator } from '@ngneat/spectator'; +import { createComponentFactory, Spectator } from '@ngneat/spectator/jest'; import { Button } from 'primeng/button'; import { SplitButton, SplitButtonModule } from 'primeng/splitbutton'; @@ -128,7 +128,7 @@ describe('DotWorkflowActionsComponent', () => { }); it('should emit the action when click on a split button', () => { - const spy = spyOn(spectator.component.actionFired, 'emit'); + const spy = jest.spyOn(spectator.component.actionFired, 'emit'); const splitButton = spectator.query('.p-splitbutton > button'); splitButton.dispatchEvent(new Event('click')); diff --git a/core-web/libs/ui/src/lib/directives/dot-select-item/dot-select-item.directive.spec.ts b/core-web/libs/ui/src/lib/directives/dot-select-item/dot-select-item.directive.spec.ts index 1aa0232269fc..51366c68fc46 100644 --- a/core-web/libs/ui/src/lib/directives/dot-select-item/dot-select-item.directive.spec.ts +++ b/core-web/libs/ui/src/lib/directives/dot-select-item/dot-select-item.directive.spec.ts @@ -1,6 +1,4 @@ -import { SpectatorDirective, createDirectiveFactory } from '@ngneat/spectator'; - -import { By } from '@angular/platform-browser'; +import { SpectatorDirective, createDirectiveFactory } from '@ngneat/spectator/jest'; import { AutoComplete, AutoCompleteModule } from 'primeng/autocomplete'; @@ -9,8 +7,8 @@ import { DotSelectItemDirective } from './dot-select-item.directive'; describe('DotSelectItemDirective', () => { let spectator: SpectatorDirective; let autoComplete: AutoComplete; - let onKeyUpMock: jasmine.Spy; - let selectItem: jasmine.Spy; + let onKeyUpMock: jest.SpyInstance; + let selectItem: jest.SpyInstance; const createDirective = createDirectiveFactory({ directive: DotSelectItemDirective, @@ -20,9 +18,9 @@ describe('DotSelectItemDirective', () => { beforeEach(() => { spectator = createDirective(); - autoComplete = spectator.debugElement.query(By.css('p-autoComplete')).componentInstance; - onKeyUpMock = spyOn(spectator.directive, 'onKeyUp').and.callThrough(); - selectItem = spyOn(autoComplete, 'selectItem'); + autoComplete = spectator.query(AutoComplete); + onKeyUpMock = jest.spyOn(spectator.directive, 'onKeyUp').mockImplementation(); + selectItem = jest.spyOn(autoComplete, 'selectItem'); }); it('should call onKeyUp from the directive', () => { @@ -33,7 +31,7 @@ describe('DotSelectItemDirective', () => { spectator.triggerEventHandler('p-autoComplete[dotSelectItem]', 'onKeyUp', event); - expect(onKeyUpMock).toHaveBeenCalledOnceWith(event); + expect(onKeyUpMock).toHaveBeenCalledWith(event); }); it('should call autoComplete selectItem when key is "Enter"', () => { @@ -44,7 +42,7 @@ describe('DotSelectItemDirective', () => { spectator.triggerEventHandler('p-autoComplete[dotSelectItem]', 'onKeyUp', event); - expect(selectItem).toHaveBeenCalledOnceWith(event.target.value); + expect(selectItem).toHaveBeenCalledWith(event.target.value); }); it('should not call autoComplete selectItem when key is not "Enter"', () => { diff --git a/core-web/libs/ui/src/lib/directives/dot-trim-input/dot-trim-input.directive.spec.ts b/core-web/libs/ui/src/lib/directives/dot-trim-input/dot-trim-input.directive.spec.ts index 0466ac448ce0..8cbe87e41273 100644 --- a/core-web/libs/ui/src/lib/directives/dot-trim-input/dot-trim-input.directive.spec.ts +++ b/core-web/libs/ui/src/lib/directives/dot-trim-input/dot-trim-input.directive.spec.ts @@ -1,4 +1,4 @@ -import { byTestId, createComponentFactory, Spectator } from '@ngneat/spectator'; +import { byTestId, createComponentFactory, Spectator } from '@ngneat/spectator/jest'; import { Component } from '@angular/core'; import { FormsModule, NgControl } from '@angular/forms'; @@ -32,7 +32,7 @@ describe('DotTrimInputDirective', () => { await spectator.fixture.whenStable(); - expect(spectator.query(byTestId('input-to-trim'))).toExist(); + expect(spectator.query(byTestId('input-to-trim'))).not.toBeNull(); expect(input.value).toBe(STRING_WITH_SPACES); spectator.dispatchFakeEvent(input, 'blur'); diff --git a/core-web/libs/ui/src/lib/dot-container-options/dot-container-options.directive.spec.ts b/core-web/libs/ui/src/lib/dot-container-options/dot-container-options.directive.spec.ts index 4f78b46d3ca1..fd2421b9948a 100644 --- a/core-web/libs/ui/src/lib/dot-container-options/dot-container-options.directive.spec.ts +++ b/core-web/libs/ui/src/lib/dot-container-options/dot-container-options.directive.spec.ts @@ -1,4 +1,4 @@ -import { createHostFactory, SpectatorHost } from '@ngneat/spectator'; +import { createHostFactory, SpectatorHost } from '@ngneat/spectator/jest'; import { By } from '@angular/platform-browser'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; diff --git a/core-web/libs/ui/src/lib/dot-remove-confirm-popup/dot-remove-confirm-popup.directive.spec.ts b/core-web/libs/ui/src/lib/dot-remove-confirm-popup/dot-remove-confirm-popup.directive.spec.ts index 67e4f957a273..84a005efb429 100644 --- a/core-web/libs/ui/src/lib/dot-remove-confirm-popup/dot-remove-confirm-popup.directive.spec.ts +++ b/core-web/libs/ui/src/lib/dot-remove-confirm-popup/dot-remove-confirm-popup.directive.spec.ts @@ -1,4 +1,4 @@ -import { createHostFactory, SpectatorHost } from '@ngneat/spectator'; +import { createHostFactory, SpectatorHost } from '@ngneat/spectator/jest'; import { Component } from '@angular/core'; diff --git a/core-web/libs/ui/src/lib/dot-site-selector/dot-site-selector.directive.spec.ts b/core-web/libs/ui/src/lib/dot-site-selector/dot-site-selector.directive.spec.ts index f08ae393d497..4a105972655b 100644 --- a/core-web/libs/ui/src/lib/dot-site-selector/dot-site-selector.directive.spec.ts +++ b/core-web/libs/ui/src/lib/dot-site-selector/dot-site-selector.directive.spec.ts @@ -1,4 +1,4 @@ -import { createDirectiveFactory, SpectatorDirective } from '@ngneat/spectator'; +import { createDirectiveFactory, SpectatorDirective } from '@ngneat/spectator/jest'; import { of } from 'rxjs'; import { HttpClientTestingModule } from '@angular/common/http/testing'; diff --git a/core-web/libs/ui/src/lib/dot-tab-buttons/dot-tab-buttons.component.spec.ts b/core-web/libs/ui/src/lib/dot-tab-buttons/dot-tab-buttons.component.spec.ts index 01c9bc111058..78655840494a 100644 --- a/core-web/libs/ui/src/lib/dot-tab-buttons/dot-tab-buttons.component.spec.ts +++ b/core-web/libs/ui/src/lib/dot-tab-buttons/dot-tab-buttons.component.spec.ts @@ -1,4 +1,5 @@ -import { byTestId, createComponentFactory, Spectator } from '@ngneat/spectator'; +import { createMouseEvent } from '@ngneat/spectator'; +import { byTestId, createComponentFactory, Spectator } from '@ngneat/spectator/jest'; import { NgClass, NgFor, NgIf } from '@angular/common'; import { HttpClientTestingModule } from '@angular/common/http/testing'; @@ -17,7 +18,10 @@ import { DotTabButtonsComponent } from './dot-tab-buttons.component'; describe('DotTabButtonsComponent', () => { let spectator: Spectator; - const pointerEvent = new PointerEvent('click'); + + // Pointer event API is not available in jest, but a MouseEvent works fine. + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const pointerEvent = createMouseEvent('click') as any; let editID: string; let previewID: string; @@ -63,7 +67,7 @@ describe('DotTabButtonsComponent', () => { }); it('should emit openMenu event when showMenu is called', () => { - const openMenuSpy = spyOn(spectator.component.openMenu, 'emit'); + const openMenuSpy = jest.spyOn(spectator.component.openMenu, 'emit'); const tab = spectator.queryAll(byTestId('dot-tab-container'))[1] as HTMLElement; const button = spectator.fixture.debugElement.queryAll( By.css('[data-testId="dot-tab-button-text"]') @@ -81,7 +85,7 @@ describe('DotTabButtonsComponent', () => { }); it('should emit openMenu event when showMenu is called', () => { - const openMenuSpy = spyOn(spectator.component.openMenu, 'emit'); + const openMenuSpy = jest.spyOn(spectator.component.openMenu, 'emit'); const tab = spectator.queryAll(byTestId('dot-tab-container'))[1] as HTMLElement; const button = spectator.fixture.debugElement.queryAll( @@ -104,7 +108,7 @@ describe('DotTabButtonsComponent', () => { }); it('should not emit openMenu event when showMenu is called and the option does not have showDropdownButton setted to true', () => { - const openMenuSpy = spyOn(spectator.component.openMenu, 'emit'); + const openMenuSpy = jest.spyOn(spectator.component.openMenu, 'emit'); spectator.component.onClickDropdown(pointerEvent, editID); const tab = spectator.queryAll(byTestId('dot-tab-container'))[1] as HTMLElement; @@ -116,7 +120,7 @@ describe('DotTabButtonsComponent', () => { }); it('should emit clickOption event when onClickOption is called with a PREVIEW value', () => { - const clickOptionSpy = spyOn(spectator.component.clickOption, 'emit'); + const clickOptionSpy = jest.spyOn(spectator.component.clickOption, 'emit'); spectator.component.activeId = DotPageMode.EDIT; const button = spectator.fixture.debugElement.queryAll( @@ -132,17 +136,17 @@ describe('DotTabButtonsComponent', () => { }); it('should not emit clickOption event when onClickOption is called if the user is in the same tab', () => { - const clickOptionSpy = spyOn(spectator.component.clickOption, 'emit'); + const clickOptionSpy = jest.spyOn(spectator.component.clickOption, 'emit'); const button = spectator.queryAll(byTestId('dot-tab-button-text'))[1]; - button.dispatchEvent(new PointerEvent('click')); + button.dispatchEvent(pointerEvent); expect(clickOptionSpy).not.toHaveBeenCalled(); }); it('should call showMenu when onClickDropdown is called ', () => { - const openMenuSpy = spyOn(spectator.component.openMenu, 'emit'); + const openMenuSpy = jest.spyOn(spectator.component.openMenu, 'emit'); const button = spectator.queryAll(byTestId('dot-tab-button-dropdown'))[0]; const tab = spectator.queryAll(byTestId('dot-tab-container'))[1] as HTMLElement; diff --git a/core-web/libs/ui/src/lib/pipes/dot-file-size-format/dot-file-size-format.pipe.spec.ts b/core-web/libs/ui/src/lib/pipes/dot-file-size-format/dot-file-size-format.pipe.spec.ts index 8a0c9a7628bf..dd04ac110adb 100644 --- a/core-web/libs/ui/src/lib/pipes/dot-file-size-format/dot-file-size-format.pipe.spec.ts +++ b/core-web/libs/ui/src/lib/pipes/dot-file-size-format/dot-file-size-format.pipe.spec.ts @@ -1,4 +1,4 @@ -import { createPipeFactory, SpectatorPipe } from '@ngneat/spectator'; +import { createPipeFactory, SpectatorPipe } from '@ngneat/spectator/jest'; import { DotFileSizeFormatPipe } from './dot-file-size-format.pipe'; diff --git a/core-web/libs/ui/src/lib/pipes/dot-timestamp-to-date/dot-timestamp-to-date.pipe.spec.ts b/core-web/libs/ui/src/lib/pipes/dot-timestamp-to-date/dot-timestamp-to-date.pipe.spec.ts index 3376d8db5dbb..1003b01aa1b7 100644 --- a/core-web/libs/ui/src/lib/pipes/dot-timestamp-to-date/dot-timestamp-to-date.pipe.spec.ts +++ b/core-web/libs/ui/src/lib/pipes/dot-timestamp-to-date/dot-timestamp-to-date.pipe.spec.ts @@ -1,4 +1,4 @@ -import { createPipeFactory, mockProvider, SpectatorPipe } from '@ngneat/spectator'; +import { createPipeFactory, mockProvider, SpectatorPipe } from '@ngneat/spectator/jest'; import { DotFormatDateService } from '@dotcms/data-access'; diff --git a/core-web/libs/ui/src/lib/resolvers/dot-enterprise-license-resolver.service.spec.ts b/core-web/libs/ui/src/lib/resolvers/dot-enterprise-license-resolver.service.spec.ts index da2162e19d43..6b4ca7385e35 100644 --- a/core-web/libs/ui/src/lib/resolvers/dot-enterprise-license-resolver.service.spec.ts +++ b/core-web/libs/ui/src/lib/resolvers/dot-enterprise-license-resolver.service.spec.ts @@ -25,7 +25,7 @@ describe('DotEnterpriseLicenseResolver', () => { }); it('should call dotLicenseService', () => { - spyOn(dotLicenseService, 'isEnterprise').and.returnValue(of(true)); + jest.spyOn(dotLicenseService, 'isEnterprise').mockReturnValue(of(true)); service.resolve().subscribe(() => { expect(dotLicenseService.isEnterprise).toHaveBeenCalled(); }); diff --git a/core-web/libs/ui/src/lib/resolvers/dot-portlet-hace-license.resolver.spec.ts b/core-web/libs/ui/src/lib/resolvers/dot-portlet-hace-license.resolver.spec.ts index ba4e50731cf0..274afb217a36 100644 --- a/core-web/libs/ui/src/lib/resolvers/dot-portlet-hace-license.resolver.spec.ts +++ b/core-web/libs/ui/src/lib/resolvers/dot-portlet-hace-license.resolver.spec.ts @@ -32,7 +32,7 @@ describe('formResolver', () => { const resolver = runInInjectionContext(TestBed.inject(EnvironmentInjector), () => portletHaveLicenseResolver({}, { url: '' } as RouterStateSnapshot) ); - spyOn(dotLicenseService, 'canAccessEnterprisePortlet').and.returnValue(of(true)); + jest.spyOn(dotLicenseService, 'canAccessEnterprisePortlet').mockReturnValue(of(true)); resolver.subscribe((res) => { expect(res).toBe(true); }); @@ -42,7 +42,7 @@ describe('formResolver', () => { const resolver = runInInjectionContext(TestBed.inject(EnvironmentInjector), () => portletHaveLicenseResolver({}, { url: '' } as RouterStateSnapshot) ); - spyOn(dotLicenseService, 'canAccessEnterprisePortlet').and.returnValue(of(false)); + jest.spyOn(dotLicenseService, 'canAccessEnterprisePortlet').mockReturnValue(of(false)); resolver.subscribe((res) => { expect(res).toBe(true); }); diff --git a/core-web/libs/ui/src/lib/resolvers/dot-push-publish-enviroments-resolver.service.spec.ts b/core-web/libs/ui/src/lib/resolvers/dot-push-publish-enviroments-resolver.service.spec.ts index 43920b5f64d4..ab19db2f497e 100644 --- a/core-web/libs/ui/src/lib/resolvers/dot-push-publish-enviroments-resolver.service.spec.ts +++ b/core-web/libs/ui/src/lib/resolvers/dot-push-publish-enviroments-resolver.service.spec.ts @@ -29,7 +29,7 @@ describe('DotPushPublishEnvironmentsResolver', () => { }); it('should get a list of environments', () => { - spyOn(pushPublishService, 'getEnvironments').and.returnValue(of([])); + jest.spyOn(pushPublishService, 'getEnvironments').mockReturnValue(of([])); service.resolve().subscribe(() => { expect(pushPublishService.getEnvironments).toHaveBeenCalled(); }); diff --git a/core-web/libs/ui/src/lib/services/clipboard/ClipboardUtil.spec.ts b/core-web/libs/ui/src/lib/services/clipboard/ClipboardUtil.spec.ts index 71a2f9edd6db..6c2c21185fe1 100644 --- a/core-web/libs/ui/src/lib/services/clipboard/ClipboardUtil.spec.ts +++ b/core-web/libs/ui/src/lib/services/clipboard/ClipboardUtil.spec.ts @@ -15,7 +15,7 @@ describe('DotClipboardUtil', () => { }); it('should copy', () => { - spyOn(document, 'execCommand').and.returnValue(true); + jest.spyOn(document, 'execCommand').mockReturnValue(true); service.copy('hello-world').then((res: boolean) => { expect(res).toBe(true); @@ -24,7 +24,9 @@ describe('DotClipboardUtil', () => { }); it('should not copy and habdle error', () => { - spyOn(document, 'execCommand').and.throwError('failed'); + jest.spyOn(document, 'execCommand').mockImplementation(() => { + throw new Error(); + }); service .copy('hello-world') diff --git a/core-web/libs/ui/src/test-setup.ts b/core-web/libs/ui/src/test-setup.ts new file mode 100644 index 000000000000..d69ec33e305c --- /dev/null +++ b/core-web/libs/ui/src/test-setup.ts @@ -0,0 +1,13 @@ +// Configure Jest for Angular [https://medium.com/@kyjungok/setup-jest-in-angular-application-22b22609cbcd] +import 'jest-preset-angular/setup-jest'; + +import { NgModule } from '@angular/core'; + +// This is needed to mock the PrimeNG SplitButton component to avoid errors while running tests. +// https://github.com/primefaces/primeng/issues/12945 +@NgModule() +export class SplitButtonMockModule {} + +jest.mock('primeng/splitbutton', () => ({ + SplitButtonModule: SplitButtonMockModule +})); diff --git a/core-web/libs/ui/src/test.ts b/core-web/libs/ui/src/test.ts deleted file mode 100644 index d8edc3e0f4ff..000000000000 --- a/core-web/libs/ui/src/test.ts +++ /dev/null @@ -1,15 +0,0 @@ -// This file is required by karma.conf.js and loads recursively all the .spec and framework files - -import 'zone.js'; - -import 'zone.js/testing'; -import { getTestBed } from '@angular/core/testing'; -import { - BrowserDynamicTestingModule, - platformBrowserDynamicTesting -} from '@angular/platform-browser-dynamic/testing'; - -// First, initialize the Angular testing environment. -getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting(), { - teardown: { destroyAfterEach: false } -}); diff --git a/core-web/libs/ui/tsconfig.spec.json b/core-web/libs/ui/tsconfig.spec.json index f0d2a64f174d..6111978e3371 100644 --- a/core-web/libs/ui/tsconfig.spec.json +++ b/core-web/libs/ui/tsconfig.spec.json @@ -2,10 +2,10 @@ "extends": "./tsconfig.json", "compilerOptions": { "outDir": "../../dist/out-tsc", - "types": ["jasmine", "node"], + "types": ["jest", "node"], "target": "ES2022", "useDefineForClassFields": false }, - "files": ["src/test.ts"], - "include": ["**/*.spec.ts", "**/*.d.ts"] + "files": ["src/test-setup.ts"], + "include": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.d.ts"] }