Browse Source

tests updated

pull/24530/head
erdemcaygor 1 month ago
parent
commit
ac7c80a5a1
  1. 4
      npm/ng-packs/packages/core/src/lib/tests/autofocus.directive.spec.ts
  2. 42
      npm/ng-packs/packages/core/src/lib/tests/config-state.service.spec.ts
  3. 6
      npm/ng-packs/packages/core/src/lib/tests/container.strategy.spec.ts
  4. 2
      npm/ng-packs/packages/core/src/lib/tests/content-projection.service.spec.ts
  5. 8
      npm/ng-packs/packages/core/src/lib/tests/content.strategy.spec.ts
  6. 2
      npm/ng-packs/packages/core/src/lib/tests/context.strategy.spec.ts
  7. 26
      npm/ng-packs/packages/core/src/lib/tests/date-utils.spec.ts
  8. 6
      npm/ng-packs/packages/core/src/lib/tests/debounce.directive.spec.ts
  9. 10
      npm/ng-packs/packages/core/src/lib/tests/dynamic-layout.component.spec.ts
  10. 8
      npm/ng-packs/packages/core/src/lib/tests/environment-utils.spec.ts
  11. 6
      npm/ng-packs/packages/core/src/lib/tests/form-submit.directive.spec.ts
  12. 17
      npm/ng-packs/packages/core/src/lib/tests/internal-store.spec.ts
  13. 198
      npm/ng-packs/packages/core/src/lib/tests/internet-connection.service.spec.ts
  14. 106
      npm/ng-packs/packages/core/src/lib/tests/lazy-load-utils.spec.ts
  15. 8
      npm/ng-packs/packages/core/src/lib/tests/lazy-load.service.spec.ts
  16. 3
      npm/ng-packs/packages/core/src/lib/tests/list.service.spec.ts
  17. 4
      npm/ng-packs/packages/core/src/lib/tests/loading.strategy.spec.ts
  18. 12
      npm/ng-packs/packages/core/src/lib/tests/local-storage.service.spec.ts
  19. 4
      npm/ng-packs/packages/core/src/lib/tests/localization.pipe.spec.ts
  20. 22
      npm/ng-packs/packages/core/src/lib/tests/localization.service.spec.ts
  21. 8
      npm/ng-packs/packages/core/src/lib/tests/multi-tenancy-utils.spec.ts
  22. 6
      npm/ng-packs/packages/core/src/lib/tests/permission.directive.spec.ts
  23. 10
      npm/ng-packs/packages/core/src/lib/tests/replaceable-template.directive.spec.ts
  24. 9
      npm/ng-packs/packages/core/src/lib/tests/rest.service.spec.ts
  25. 4
      npm/ng-packs/packages/core/src/lib/tests/route-utils.spec.ts
  26. 2
      npm/ng-packs/packages/core/src/lib/tests/router-events.service.spec.ts
  27. 2
      npm/ng-packs/packages/core/src/lib/tests/router-outlet.component.spec.ts
  28. 4
      npm/ng-packs/packages/core/src/lib/tests/routes.handler.spec.ts
  29. 30
      npm/ng-packs/packages/core/src/lib/tests/routes.service.spec.ts
  30. 4
      npm/ng-packs/packages/core/src/lib/tests/safe-html.pipe.spec.ts
  31. 108
      npm/ng-packs/packages/core/src/lib/tests/show-password-directive.spec.ts
  32. 2
      npm/ng-packs/packages/core/src/lib/tests/sort.pipe.spec.ts
  33. 6
      npm/ng-packs/packages/core/src/lib/tests/stop-propagation.directive.spec.ts
  34. 6
      npm/ng-packs/packages/core/src/lib/tests/subscription.service.spec.ts

4
npm/ng-packs/packages/core/src/lib/tests/autofocus.directive.spec.ts

@ -1,6 +1,6 @@
import { createDirectiveFactory, SpectatorDirective } from '@ngneat/spectator/jest'; import { createDirectiveFactory, SpectatorDirective } from '@ngneat/spectator/vitest';
import { AutofocusDirective } from '../directives/autofocus.directive'; import { AutofocusDirective } from '../directives/autofocus.directive';
import { timer } from 'rxjs'; import { timer , firstValueFrom } from 'rxjs';
describe('AutofocusDirective', () => { describe('AutofocusDirective', () => {
let spectator: SpectatorDirective<AutofocusDirective>; let spectator: SpectatorDirective<AutofocusDirective>;

42
npm/ng-packs/packages/core/src/lib/tests/config-state.service.spec.ts

@ -1,6 +1,6 @@
import { provideHttpClientTesting } from '@angular/common/http/testing'; import { provideHttpClientTesting } from '@angular/common/http/testing';
import { provideHttpClient } from '@angular/common/http'; import { provideHttpClient } from '@angular/common/http';
import { createServiceFactory, SpectatorService } from '@ngneat/spectator/jest'; import { createServiceFactory, SpectatorService } from '@ngneat/spectator/vitest';
import { of } from 'rxjs'; import { of } from 'rxjs';
import { AbpApplicationConfigurationService } from '../proxy/volo/abp/asp-net-core/mvc/application-configurations/abp-application-configuration.service'; import { AbpApplicationConfigurationService } from '../proxy/volo/abp/asp-net-core/mvc/application-configurations/abp-application-configuration.service';
import { import {
@ -142,84 +142,84 @@ describe('ConfigStateService', () => {
spectator = createService(); spectator = createService();
configState = spectator.service; configState = spectator.service;
jest.spyOn(configState, 'getAll').mockReturnValue(CONFIG_STATE_DATA); vi.spyOn(configState, 'getAll').mockReturnValue(CONFIG_STATE_DATA);
jest.spyOn(configState, 'getAll$').mockReturnValue(of(CONFIG_STATE_DATA)); vi.spyOn(configState, 'getAll$').mockReturnValue(of(CONFIG_STATE_DATA));
jest.spyOn(configState, 'getOne').mockImplementation((key) => { vi.spyOn(configState, 'getOne').mockImplementation((key) => {
if (key === 'localization') return CONFIG_STATE_DATA.localization; if (key === 'localization') return CONFIG_STATE_DATA.localization;
return undefined; return undefined;
}); });
jest.spyOn(configState, 'getOne$').mockImplementation((key) => { vi.spyOn(configState, 'getOne$').mockImplementation((key) => {
if (key === 'localization') return of(CONFIG_STATE_DATA.localization); if (key === 'localization') return of(CONFIG_STATE_DATA.localization);
return of(undefined); return of(undefined);
}); });
jest.spyOn(configState, 'getDeep').mockImplementation((key) => { vi.spyOn(configState, 'getDeep').mockImplementation((key) => {
if (key === 'localization.languages') return CONFIG_STATE_DATA.localization.languages; if (key === 'localization.languages') return CONFIG_STATE_DATA.localization.languages;
if (key === 'test') return undefined; if (key === 'test') return undefined;
return undefined; return undefined;
}); });
jest.spyOn(configState, 'getDeep$').mockImplementation((key) => { vi.spyOn(configState, 'getDeep$').mockImplementation((key) => {
if (key === 'localization.languages') return of(CONFIG_STATE_DATA.localization.languages); if (key === 'localization.languages') return of(CONFIG_STATE_DATA.localization.languages);
return of(undefined); return of(undefined);
}); });
jest.spyOn(configState, 'getFeature').mockImplementation((key) => { vi.spyOn(configState, 'getFeature').mockImplementation((key) => {
if (key === 'Chat.Enable') return CONFIG_STATE_DATA.features.values['Chat.Enable']; if (key === 'Chat.Enable') return CONFIG_STATE_DATA.features.values['Chat.Enable'];
return undefined; return undefined;
}); });
jest.spyOn(configState, 'getFeature$').mockImplementation((key) => { vi.spyOn(configState, 'getFeature$').mockImplementation((key) => {
if (key === 'Chat.Enable') return of(CONFIG_STATE_DATA.features.values['Chat.Enable']); if (key === 'Chat.Enable') return of(CONFIG_STATE_DATA.features.values['Chat.Enable']);
return of(undefined); return of(undefined);
}); });
jest.spyOn(configState, 'getSetting').mockImplementation((key) => { vi.spyOn(configState, 'getSetting').mockImplementation((key) => {
if (key === 'Abp.Localization.DefaultLanguage') return CONFIG_STATE_DATA.setting.values['Abp.Localization.DefaultLanguage']; if (key === 'Abp.Localization.DefaultLanguage') return CONFIG_STATE_DATA.setting.values['Abp.Localization.DefaultLanguage'];
return undefined; return undefined;
}); });
jest.spyOn(configState, 'getSetting$').mockImplementation((key) => { vi.spyOn(configState, 'getSetting$').mockImplementation((key) => {
if (key === 'Abp.Localization.DefaultLanguage') return of(CONFIG_STATE_DATA.setting.values['Abp.Localization.DefaultLanguage']); if (key === 'Abp.Localization.DefaultLanguage') return of(CONFIG_STATE_DATA.setting.values['Abp.Localization.DefaultLanguage']);
return of(undefined); return of(undefined);
}); });
jest.spyOn(configState, 'getSettings').mockImplementation((keyword) => { vi.spyOn(configState, 'getSettings').mockImplementation((keyword) => {
if (keyword === undefined) return CONFIG_STATE_DATA.setting.values; if (keyword === undefined) return CONFIG_STATE_DATA.setting.values;
if (keyword === 'localization') return { 'Abp.Localization.DefaultLanguage': 'en' }; if (keyword === 'localization') return { 'Abp.Localization.DefaultLanguage': 'en' };
if (keyword === 'Localization') return { 'Abp.Localization.DefaultLanguage': 'en' }; if (keyword === 'Localization') return { 'Abp.Localization.DefaultLanguage': 'en' };
return {}; return {};
}); });
jest.spyOn(configState, 'getSettings$').mockImplementation((keyword) => { vi.spyOn(configState, 'getSettings$').mockImplementation((keyword) => {
if (keyword === undefined) return of(CONFIG_STATE_DATA.setting.values); if (keyword === undefined) return of(CONFIG_STATE_DATA.setting.values);
if (keyword === 'localization') return of({ 'Abp.Localization.DefaultLanguage': 'en' }); if (keyword === 'localization') return of({ 'Abp.Localization.DefaultLanguage': 'en' });
if (keyword === 'Localization') return of({ 'Abp.Localization.DefaultLanguage': 'en' }); if (keyword === 'Localization') return of({ 'Abp.Localization.DefaultLanguage': 'en' });
return of({}); return of({});
}); });
jest.spyOn(configState, 'getFeatures').mockImplementation((keys) => { vi.spyOn(configState, 'getFeatures').mockImplementation((keys) => {
if (keys.includes('Chat.Enable')) { if (keys.includes('Chat.Enable')) {
return { 'Chat.Enable': 'True' }; return { 'Chat.Enable': 'True' };
} }
return {}; return {};
}); });
jest.spyOn(configState, 'getFeatures$').mockImplementation((keys) => { vi.spyOn(configState, 'getFeatures$').mockImplementation((keys) => {
if (keys.includes('Chat.Enable')) { if (keys.includes('Chat.Enable')) {
return of({ 'Chat.Enable': 'True' }); return of({ 'Chat.Enable': 'True' });
} }
return of({}); return of({});
}); });
jest.spyOn(configState, 'getFeatureIsEnabled').mockImplementation((key) => { vi.spyOn(configState, 'getFeatureIsEnabled').mockImplementation((key) => {
if (key === 'Chat.Enable') return true; if (key === 'Chat.Enable') return true;
return false; return false;
}); });
jest.spyOn(configState, 'getFeatureIsEnabled$').mockImplementation((key) => { vi.spyOn(configState, 'getFeatureIsEnabled$').mockImplementation((key) => {
if (key === 'Chat.Enable') return of(true); if (key === 'Chat.Enable') return of(true);
return of(false); return of(false);
}); });
jest.spyOn(configState, 'getGlobalFeatures').mockReturnValue({ vi.spyOn(configState, 'getGlobalFeatures').mockReturnValue({
enabledFeatures: ['Feature1', 'Feature2'] enabledFeatures: ['Feature1', 'Feature2']
}); });
jest.spyOn(configState, 'getGlobalFeatures$').mockReturnValue(of({ vi.spyOn(configState, 'getGlobalFeatures$').mockReturnValue(of({
enabledFeatures: ['Feature1', 'Feature2'] enabledFeatures: ['Feature1', 'Feature2']
})); }));
jest.spyOn(configState, 'getGlobalFeatureIsEnabled').mockImplementation((key) => { vi.spyOn(configState, 'getGlobalFeatureIsEnabled').mockImplementation((key) => {
if (key === 'Feature1') return true; if (key === 'Feature1') return true;
return false; return false;
}); });
jest.spyOn(configState, 'getGlobalFeatureIsEnabled$').mockImplementation((key) => { vi.spyOn(configState, 'getGlobalFeatureIsEnabled$').mockImplementation((key) => {
if (key === 'Feature1') return of(true); if (key === 'Feature1') return of(true);
return of(false); return of(false);
}); });

6
npm/ng-packs/packages/core/src/lib/tests/container.strategy.spec.ts

@ -7,7 +7,7 @@ import {
describe('ClearContainerStrategy', () => { describe('ClearContainerStrategy', () => {
const containerRef = { const containerRef = {
clear: jest.fn(), clear: vi.fn(),
length: 7, length: 7,
} as any as ViewContainerRef; } as any as ViewContainerRef;
@ -30,7 +30,7 @@ describe('ClearContainerStrategy', () => {
describe('InsertIntoContainerStrategy', () => { describe('InsertIntoContainerStrategy', () => {
const containerRef = { const containerRef = {
clear: jest.fn(), clear: vi.fn(),
length: 7, length: 7,
} as any as ViewContainerRef; } as any as ViewContainerRef;
@ -62,7 +62,7 @@ describe('InsertIntoContainerStrategy', () => {
describe('CONTAINER_STRATEGY', () => { describe('CONTAINER_STRATEGY', () => {
const containerRef = { const containerRef = {
clear: jest.fn(), clear: vi.fn(),
length: 7, length: 7,
} as any as ViewContainerRef; } as any as ViewContainerRef;

2
npm/ng-packs/packages/core/src/lib/tests/content-projection.service.spec.ts

@ -1,5 +1,5 @@
import { Component, ComponentRef } from '@angular/core'; import { Component, ComponentRef } from '@angular/core';
import { createServiceFactory, SpectatorService } from '@ngneat/spectator/jest'; import { createServiceFactory, SpectatorService } from '@ngneat/spectator/vitest';
import { ContentProjectionService } from '../services'; import { ContentProjectionService } from '../services';
import { PROJECTION_STRATEGY } from '../strategies'; import { PROJECTION_STRATEGY } from '../strategies';

8
npm/ng-packs/packages/core/src/lib/tests/content.strategy.spec.ts

@ -22,8 +22,8 @@ describe('StyleContentStrategy', () => {
const domStrategy = DOM_STRATEGY.PrependToHead(); const domStrategy = DOM_STRATEGY.PrependToHead();
const contentSecurityStrategy = CONTENT_SECURITY_STRATEGY.None(); const contentSecurityStrategy = CONTENT_SECURITY_STRATEGY.None();
contentSecurityStrategy.applyCSP = jest.fn((el: HTMLScriptElement) => {}); contentSecurityStrategy.applyCSP = vi.fn((el: HTMLScriptElement) => {});
domStrategy.insertElement = jest.fn((el: HTMLScriptElement) => {}) as any; domStrategy.insertElement = vi.fn((el: HTMLScriptElement) => {}) as any;
const strategy = new StyleContentStrategy('', domStrategy, contentSecurityStrategy); const strategy = new StyleContentStrategy('', domStrategy, contentSecurityStrategy);
strategy.createElement(); strategy.createElement();
@ -53,8 +53,8 @@ describe('ScriptContentStrategy', () => {
const domStrategy = DOM_STRATEGY.PrependToHead(); const domStrategy = DOM_STRATEGY.PrependToHead();
const contentSecurityStrategy = CONTENT_SECURITY_STRATEGY.Loose(nonce); const contentSecurityStrategy = CONTENT_SECURITY_STRATEGY.Loose(nonce);
contentSecurityStrategy.applyCSP = jest.fn((el: HTMLScriptElement) => {}); contentSecurityStrategy.applyCSP = vi.fn((el: HTMLScriptElement) => {});
domStrategy.insertElement = jest.fn((el: HTMLScriptElement) => {}) as any; domStrategy.insertElement = vi.fn((el: HTMLScriptElement) => {}) as any;
const strategy = new ScriptContentStrategy('', domStrategy, contentSecurityStrategy); const strategy = new ScriptContentStrategy('', domStrategy, contentSecurityStrategy);
const element = strategy.createElement(); const element = strategy.createElement();

2
npm/ng-packs/packages/core/src/lib/tests/context.strategy.spec.ts

@ -20,7 +20,7 @@ describe('ComponentContextStrategy', () => {
z: '', z: '',
}, },
changeDetectorRef: { changeDetectorRef: {
detectChanges: jest.fn(), detectChanges: vi.fn(),
}, },
} as any), } as any),
); );

26
npm/ng-packs/packages/core/src/lib/tests/date-utils.spec.ts

@ -1,6 +1,6 @@
import { ConfigStateService } from '../services'; import { ConfigStateService } from '../services';
import { getShortDateFormat, getShortDateShortTimeFormat, getShortTimeFormat } from '../utils'; import { getShortDateFormat, getShortDateShortTimeFormat, getShortTimeFormat } from '../utils';
import { createServiceFactory, SpectatorService } from '@ngneat/spectator/jest'; import { createServiceFactory, SpectatorService } from '@ngneat/spectator/vitest';
import { CORE_OPTIONS } from '../tokens/options.token'; import { CORE_OPTIONS } from '../tokens/options.token';
import { HttpClient } from '@angular/common/http'; import { HttpClient } from '@angular/common/http';
import { AbpApplicationConfigurationService } from '../proxy/volo/abp/asp-net-core/mvc/application-configurations/abp-application-configuration.service'; import { AbpApplicationConfigurationService } from '../proxy/volo/abp/asp-net-core/mvc/application-configurations/abp-application-configuration.service';
@ -41,40 +41,40 @@ describe('Date Utils', () => {
{ {
provide: HttpClient, provide: HttpClient,
useValue: { useValue: {
get: jest.fn(), get: vi.fn(),
post: jest.fn(), post: vi.fn(),
put: jest.fn(), put: vi.fn(),
delete: jest.fn(), delete: vi.fn(),
}, },
}, },
{ {
provide: AbpApplicationConfigurationService, provide: AbpApplicationConfigurationService,
useValue: { useValue: {
get: jest.fn(), get: vi.fn(),
}, },
}, },
{ {
provide: RestService, provide: RestService,
useValue: { useValue: {
request: jest.fn(), request: vi.fn(),
}, },
}, },
{ {
provide: EnvironmentService, provide: EnvironmentService,
useValue: { useValue: {
getEnvironment: jest.fn(), getEnvironment: vi.fn(),
}, },
}, },
{ {
provide: HttpErrorReporterService, provide: HttpErrorReporterService,
useValue: { useValue: {
reportError: jest.fn(), reportError: vi.fn(),
}, },
}, },
{ {
provide: ExternalHttpClient, provide: ExternalHttpClient,
useValue: { useValue: {
request: jest.fn(), request: vi.fn(),
}, },
}, },
], ],
@ -87,7 +87,7 @@ describe('Date Utils', () => {
describe('#getShortDateFormat', () => { describe('#getShortDateFormat', () => {
test('should get the short date format from ConfigStateService and return it', () => { test('should get the short date format from ConfigStateService and return it', () => {
const getDeepSpy = jest.spyOn(config, 'getDeep'); const getDeepSpy = vi.spyOn(config, 'getDeep');
getDeepSpy.mockReturnValueOnce(dateTimeFormat); getDeepSpy.mockReturnValueOnce(dateTimeFormat);
expect(getShortDateFormat(config)).toBe('M/d/yyyy'); expect(getShortDateFormat(config)).toBe('M/d/yyyy');
@ -97,7 +97,7 @@ describe('Date Utils', () => {
describe('#getShortTimeFormat', () => { describe('#getShortTimeFormat', () => {
test('should get the short time format from ConfigStateService and return it', () => { test('should get the short time format from ConfigStateService and return it', () => {
const getDeepSpy = jest.spyOn(config, 'getDeep'); const getDeepSpy = vi.spyOn(config, 'getDeep');
getDeepSpy.mockReturnValueOnce(dateTimeFormat); getDeepSpy.mockReturnValueOnce(dateTimeFormat);
expect(getShortTimeFormat(config)).toBe('h:mm a'); expect(getShortTimeFormat(config)).toBe('h:mm a');
@ -107,7 +107,7 @@ describe('Date Utils', () => {
describe('#getShortDateShortTimeFormat', () => { describe('#getShortDateShortTimeFormat', () => {
test('should get the short date time format from ConfigStateService and return it', () => { test('should get the short date time format from ConfigStateService and return it', () => {
const getDeepSpy = jest.spyOn(config, 'getDeep'); const getDeepSpy = vi.spyOn(config, 'getDeep');
getDeepSpy.mockReturnValueOnce(dateTimeFormat); getDeepSpy.mockReturnValueOnce(dateTimeFormat);
expect(getShortDateShortTimeFormat(config)).toBe('M/d/yyyy h:mm a'); expect(getShortDateShortTimeFormat(config)).toBe('M/d/yyyy h:mm a');

6
npm/ng-packs/packages/core/src/lib/tests/debounce.directive.spec.ts

@ -1,12 +1,12 @@
import { createDirectiveFactory, SpectatorDirective } from '@ngneat/spectator/jest'; import { createDirectiveFactory, SpectatorDirective } from '@ngneat/spectator/vitest';
import { InputEventDebounceDirective } from '../directives/debounce.directive'; import { InputEventDebounceDirective } from '../directives/debounce.directive';
import { timer } from 'rxjs'; import { timer , firstValueFrom } from 'rxjs';
describe('InputEventDebounceDirective', () => { describe('InputEventDebounceDirective', () => {
let spectator: SpectatorDirective<InputEventDebounceDirective>; let spectator: SpectatorDirective<InputEventDebounceDirective>;
let directive: InputEventDebounceDirective; let directive: InputEventDebounceDirective;
let input: HTMLInputElement; let input: HTMLInputElement;
const inputEventFn = jest.fn(() => {}); const inputEventFn = vi.fn(() => {});
const createDirective = createDirectiveFactory({ const createDirective = createDirectiveFactory({
directive: InputEventDebounceDirective, directive: InputEventDebounceDirective,

10
npm/ng-packs/packages/core/src/lib/tests/dynamic-layout.component.spec.ts

@ -1,7 +1,7 @@
import { HttpClient } from '@angular/common/http'; import { HttpClient } from '@angular/common/http';
import { Component, NgModule, inject as inject_1 } from '@angular/core'; import { Component, NgModule, inject as inject_1 } from '@angular/core';
import { ActivatedRoute, RouterModule } from '@angular/router'; import { ActivatedRoute, RouterModule } from '@angular/router';
import { createRoutingFactory, SpectatorRouting } from '@ngneat/spectator/jest'; import { createRoutingFactory, SpectatorRouting } from '@ngneat/spectator/vitest';
import { DynamicLayoutComponent, RouterOutletComponent } from '../components'; import { DynamicLayoutComponent, RouterOutletComponent } from '../components';
import { eLayoutType } from '../enums/common'; import { eLayoutType } from '../enums/common';
import { ABP } from '../models'; import { ABP } from '../models';
@ -74,10 +74,10 @@ describe('DynamicLayoutComponent', () => {
{ {
provide: RoutesService, provide: RoutesService,
useValue: { useValue: {
add: jest.fn(), add: vi.fn(),
flat$: { pipe: jest.fn() }, flat$: { pipe: vi.fn() },
tree$: { pipe: jest.fn() }, tree$: { pipe: vi.fn() },
visible$: { pipe: jest.fn() }, visible$: { pipe: vi.fn() },
}, },
}, },
ReplaceableComponentsService, ReplaceableComponentsService,

8
npm/ng-packs/packages/core/src/lib/tests/environment-utils.spec.ts

@ -1,6 +1,6 @@
import { HttpClient } from '@angular/common/http'; import { HttpClient } from '@angular/common/http';
import { Component, Injector } from '@angular/core'; import { Component, Injector } from '@angular/core';
import { createComponentFactory, Spectator } from '@ngneat/spectator/jest'; import { createComponentFactory, Spectator } from '@ngneat/spectator/vitest';
import { BehaviorSubject } from 'rxjs'; import { BehaviorSubject } from 'rxjs';
import { Environment, RemoteEnv } from '../models/environment'; import { Environment, RemoteEnv } from '../models/environment';
import { EnvironmentService } from '../services/environment.service'; import { EnvironmentService } from '../services/environment.service';
@ -77,11 +77,11 @@ describe('EnvironmentUtils', () => {
function setupTestAndRun(strategy: Pick<RemoteEnv, 'mergeStrategy'>, expectedValue) { function setupTestAndRun(strategy: Pick<RemoteEnv, 'mergeStrategy'>, expectedValue) {
const injector = spectator.inject(Injector); const injector = spectator.inject(Injector);
const injectorSpy = jest.spyOn(injector, 'get'); const injectorSpy = vi.spyOn(injector, 'get');
const http = spectator.inject(HttpClient); const http = spectator.inject(HttpClient);
const requestSpy = jest.spyOn(http, 'request'); const requestSpy = vi.spyOn(http, 'request');
const environmentService = spectator.inject(EnvironmentService); const environmentService = spectator.inject(EnvironmentService);
const setStateSpy = jest.spyOn(environmentService, 'setState'); const setStateSpy = vi.spyOn(environmentService, 'setState');
injectorSpy.mockReturnValueOnce(environmentService); injectorSpy.mockReturnValueOnce(environmentService);
injectorSpy.mockReturnValueOnce(http); injectorSpy.mockReturnValueOnce(http);

6
npm/ng-packs/packages/core/src/lib/tests/form-submit.directive.spec.ts

@ -1,14 +1,14 @@
import { createDirectiveFactory, SpectatorDirective } from '@ngneat/spectator/jest'; import { createDirectiveFactory, SpectatorDirective } from '@ngneat/spectator/vitest';
import { FormSubmitDirective } from '../directives/form-submit.directive'; import { FormSubmitDirective } from '../directives/form-submit.directive';
import { FormsModule, ReactiveFormsModule, FormGroup } from '@angular/forms'; import { FormsModule, ReactiveFormsModule, FormGroup } from '@angular/forms';
import { timer } from 'rxjs'; import { timer , firstValueFrom } from 'rxjs';
describe('FormSubmitDirective', () => { describe('FormSubmitDirective', () => {
let spectator: SpectatorDirective<FormSubmitDirective>; let spectator: SpectatorDirective<FormSubmitDirective>;
let directive: FormSubmitDirective; let directive: FormSubmitDirective;
const formGroup = new FormGroup({}); const formGroup = new FormGroup({});
const submitEventFn = jest.fn(() => {}); const submitEventFn = vi.fn(() => {});
const createDirective = createDirectiveFactory({ const createDirective = createDirectiveFactory({
directive: FormSubmitDirective, directive: FormSubmitDirective,

17
npm/ng-packs/packages/core/src/lib/tests/internal-store.spec.ts

@ -1,5 +1,6 @@
import clone from 'just-clone'; import clone from 'just-clone';
import { take } from 'rxjs/operators'; import { take } from 'rxjs/operators';
import { firstValueFrom } from 'rxjs';
import { DeepPartial } from '../models/utility'; import { DeepPartial } from '../models/utility';
import { InternalStore } from '../utils/internal-store-utils'; import { InternalStore } from '../utils/internal-store-utils';
@ -124,18 +125,20 @@ describe('Internal Store', () => {
}); });
describe('sliceUpdate', () => { describe('sliceUpdate', () => {
it('should return slice of update$ based on selector', done => { it('should return slice of update$ based on selector', () => {
const store = new InternalStore(mockInitialState); const store = new InternalStore(mockInitialState);
const onQux$ = store.sliceUpdate(state => state.foo.bar.qux); const onQux$ = store.sliceUpdate(state => state.foo.bar.qux);
onQux$.pipe(take(1)).subscribe(value => { return new Promise<void>(resolve => {
expect(value).toEqual(deepPatch2.foo.bar.qux); onQux$.pipe(take(1)).subscribe(value => {
done(); expect(value).toEqual(deepPatch2.foo.bar.qux);
}); resolve();
});
store.deepPatch(deepPatch1); store.deepPatch(deepPatch1);
store.deepPatch(deepPatch2); store.deepPatch(deepPatch2);
});
}); });
}); });

198
npm/ng-packs/packages/core/src/lib/tests/internet-connection.service.spec.ts

@ -1,100 +1,100 @@
import { TestBed} from '@angular/core/testing'; import { TestBed} from '@angular/core/testing';
import { DOCUMENT } from '@angular/common'; import { DOCUMENT } from '@angular/common';
import { InternetConnectionService } from '../services/internet-connection-service'; import { InternetConnectionService } from '../services/internet-connection-service';
import { first } from 'rxjs'; import { first , firstValueFrom } from 'rxjs';
let service: InternetConnectionService; let service: InternetConnectionService;
describe('Internet connection when disconnected', () => { describe('Internet connection when disconnected', () => {
const events = {}; const events = {};
const addEventListener = jest.fn((event, callback) => { const addEventListener = vi.fn((event, callback) => {
events[event] = callback; events[event] = callback;
}); });
const mockDocument = { defaultView: {navigator: {onLine: false}, addEventListener } } const mockDocument = { defaultView: {navigator: {onLine: false}, addEventListener } }
beforeAll(() => { beforeAll(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
providers:[{provide:DOCUMENT, useValue: mockDocument}] providers:[{provide:DOCUMENT, useValue: mockDocument}]
}) })
service = TestBed.inject(InternetConnectionService); service = TestBed.inject(InternetConnectionService);
}); });
it('document should be created', () => { it('document should be created', () => {
expect(service.document).toEqual(mockDocument); expect(service.document).toEqual(mockDocument);
}); });
it('signal value should be false', () => { it('signal value should be false', () => {
expect(service.networkStatus()).toEqual(false); expect(service.networkStatus()).toEqual(false);
}); });
it('observable value should be false', it('observable value should be false',
(done: any) => { (done: any) => {
service.networkStatus$.pipe(first()).subscribe(value => { service.networkStatus$.pipe(first()).subscribe(value => {
expect(value).toBe(false) expect(value).toBe(false)
done(); done();
}); });
}); });
test.each(['offline','online'])('should addEventListener for %p, event',(v)=>{ test.each(['offline','online'])('should addEventListener for %p, event',(v)=>{
expect(events[v]).toBeTruthy() expect(events[v]).toBeTruthy()
}) })
test.each([['offline',false],["online",true]])('when %p called ,then signal value must be %p',(eventName,value)=>{ test.each([['offline',false],["online",true]])('when %p called ,then signal value must be %p',(eventName,value)=>{
events[eventName]() events[eventName]()
expect(service.networkStatus()).toEqual(value); expect(service.networkStatus()).toEqual(value);
}) })
test.each([['offline',false],["online",true]])('when %p called,then observable must return %p',(eventName,value)=>{ test.each([['offline',false],["online",true]])('when %p called,then observable must return %p',(eventName,value)=>{
events[eventName]() events[eventName]()
service.networkStatus$.subscribe(val=>{ service.networkStatus$.subscribe(val=>{
expect(val).toEqual(value) expect(val).toEqual(value)
}) })
}) })
}); });
describe('when connection value changes for signals', () => { describe('when connection value changes for signals', () => {
const events = {}; const events = {};
const addEventListener = jest.fn((event, callback) => { const addEventListener = vi.fn((event, callback) => {
events[event] = callback; events[event] = callback;
}); });
const mockDocument = { defaultView: {navigator: {onLine: false}, addEventListener } } const mockDocument = { defaultView: {navigator: {onLine: false}, addEventListener } }
beforeAll(() => { beforeAll(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
providers:[{provide:DOCUMENT, useValue: mockDocument}] providers:[{provide:DOCUMENT, useValue: mockDocument}]
}) })
service = TestBed.inject(InternetConnectionService); service = TestBed.inject(InternetConnectionService);
}); });
it('signal value must be false when offline event is called while internet is connected', () => { it('signal value must be false when offline event is called while internet is connected', () => {
events['online']() events['online']()
expect(service.networkStatus()).toEqual(true); expect(service.networkStatus()).toEqual(true);
events['offline']() events['offline']()
expect(service.networkStatus()).toEqual(false); expect(service.networkStatus()).toEqual(false);
}); });
it('signal value must be true when online event is called while internet is disconnected', () => { it('signal value must be true when online event is called while internet is disconnected', () => {
events['offline']() events['offline']()
expect(service.networkStatus()).toEqual(false); expect(service.networkStatus()).toEqual(false);
events['online']() events['online']()
expect(service.networkStatus()).toEqual(true); expect(service.networkStatus()).toEqual(true);
}); });
it('observable value must be false when offline event is called while internet is connected', (done:any) => { it('observable value must be false when offline event is called while internet is connected', (done:any) => {
events['online']() events['online']()
events['offline']() events['offline']()
service.networkStatus$.subscribe(val=>{ service.networkStatus$.subscribe(val=>{
expect(val).toEqual(false) expect(val).toEqual(false)
done() done()
}) })
}); });
it('observable value must be true when online event is called while internet is disconnected', (done:any) => { it('observable value must be true when online event is called while internet is disconnected', (done:any) => {
events['offline']() events['offline']()
events['online']() events['online']()
service.networkStatus$.subscribe(val=>{ service.networkStatus$.subscribe(val=>{
console.log(val); console.log(val);
expect(val).toEqual(true) expect(val).toEqual(true)
done() done()
}) })
}); });
}); });

106
npm/ng-packs/packages/core/src/lib/tests/lazy-load-utils.spec.ts

@ -6,12 +6,12 @@ import { fromLazyLoad } from '../utils/lazy-load-utils';
describe('Lazy Load Utils', () => { describe('Lazy Load Utils', () => {
describe('#fromLazyLoad', () => { describe('#fromLazyLoad', () => {
afterEach(() => { afterEach(() => {
jest.clearAllMocks(); vi.clearAllMocks();
}); });
it('should append to head by default', () => { it('should append to head by default', () => {
const element = document.createElement('link'); const element = document.createElement('link');
const spy = jest.spyOn(document.head, 'insertAdjacentElement'); const spy = vi.spyOn(document.head, 'insertAdjacentElement');
fromLazyLoad(element); fromLazyLoad(element);
expect(spy).toHaveBeenCalledWith('beforeend', element); expect(spy).toHaveBeenCalledWith('beforeend', element);
@ -19,7 +19,7 @@ describe('Lazy Load Utils', () => {
it('should allow setting a dom strategy', () => { it('should allow setting a dom strategy', () => {
const element = document.createElement('link'); const element = document.createElement('link');
const spy = jest.spyOn(document.head, 'insertAdjacentElement'); const spy = vi.spyOn(document.head, 'insertAdjacentElement');
fromLazyLoad(element, DOM_STRATEGY.PrependToHead()); fromLazyLoad(element, DOM_STRATEGY.PrependToHead());
expect(spy).toHaveBeenCalledWith('afterbegin', element); expect(spy).toHaveBeenCalledWith('afterbegin', element);
@ -52,61 +52,73 @@ describe('Lazy Load Utils', () => {
expect(element.getAttribute('integrity')).toBe(integrity); expect(element.getAttribute('integrity')).toBe(integrity);
}); });
it('should emit error event on fail and clear callbacks', done => { it('should emit error event on fail and clear callbacks', () => {
const error = new CustomEvent('error'); const error = new CustomEvent('error');
const parentNode = { removeChild: jest.fn() }; const parentNode = { removeChild: vi.fn() };
const element = { parentNode } as any as HTMLLinkElement; const element = { parentNode } as any as HTMLLinkElement;
fromLazyLoad( return new Promise<void>((resolve, reject) => {
element, fromLazyLoad(
{ element,
insertElement(el: HTMLLinkElement) { {
expect(el).toBe(element); insertElement(el: HTMLLinkElement) {
expect(el).toBe(element);
setTimeout(() => {
el.onerror(error); setTimeout(() => {
}, 0); el.onerror(error);
}, 0);
},
} as DomStrategy,
{
setCrossOrigin(_: HTMLLinkElement) {},
} as CrossOriginStrategy,
).subscribe({
error: value => {
try {
expect(value).toBe(error);
expect(parentNode.removeChild).toHaveBeenCalledWith(element);
expect(element.onerror).toBeNull();
resolve();
} catch (e) {
reject(e);
}
}, },
} as DomStrategy, });
{
setCrossOrigin(_: HTMLLinkElement) {},
} as CrossOriginStrategy,
).subscribe({
error: value => {
expect(value).toBe(error);
expect(parentNode.removeChild).toHaveBeenCalledWith(element);
expect(element.onerror).toBeNull();
done();
},
}); });
}); });
it('should emit load event on success and clear callbacks', done => { it('should emit load event on success and clear callbacks', () => {
const success = new CustomEvent('load'); const success = new CustomEvent('load');
const parentNode = { removeChild: jest.fn() }; const parentNode = { removeChild: vi.fn() };
const element = { parentNode } as any as HTMLLinkElement; const element = { parentNode } as any as HTMLLinkElement;
fromLazyLoad( return new Promise<void>((resolve, reject) => {
element, fromLazyLoad(
{ element,
insertElement(el: HTMLLinkElement) { {
expect(el).toBe(element); insertElement(el: HTMLLinkElement) {
expect(el).toBe(element);
setTimeout(() => {
el.onload(success); setTimeout(() => {
}, 0); el.onload(success);
}, 0);
},
} as DomStrategy,
{
setCrossOrigin(_: HTMLLinkElement) {},
} as CrossOriginStrategy,
).subscribe({
next: value => {
try {
expect(value).toBe(success);
expect(parentNode.removeChild).not.toHaveBeenCalled();
expect(element.onload).toBeNull();
resolve();
} catch (e) {
reject(e);
}
}, },
} as DomStrategy, });
{
setCrossOrigin(_: HTMLLinkElement) {},
} as CrossOriginStrategy,
).subscribe({
next: value => {
expect(value).toBe(success);
expect(parentNode.removeChild).not.toHaveBeenCalled();
expect(element.onload).toBeNull();
done();
},
}); });
}); });
}); });

8
npm/ng-packs/packages/core/src/lib/tests/lazy-load.service.spec.ts

@ -3,7 +3,7 @@ import { switchMap } from 'rxjs/operators';
import { LazyLoadService } from '../services/lazy-load.service'; import { LazyLoadService } from '../services/lazy-load.service';
import { ScriptLoadingStrategy } from '../strategies/loading.strategy'; import { ScriptLoadingStrategy } from '../strategies/loading.strategy';
import { ResourceWaitService } from '../services/resource-wait.service'; import { ResourceWaitService } from '../services/resource-wait.service';
import { createServiceFactory, SpectatorService } from '@ngneat/spectator/jest'; import { createServiceFactory, SpectatorService } from '@ngneat/spectator/vitest';
describe('LazyLoadService', () => { describe('LazyLoadService', () => {
let spectator: SpectatorService<LazyLoadService>; let spectator: SpectatorService<LazyLoadService>;
@ -16,8 +16,8 @@ describe('LazyLoadService', () => {
{ {
provide: ResourceWaitService, provide: ResourceWaitService,
useValue: { useValue: {
wait: jest.fn(), wait: vi.fn(),
addResource: jest.fn(), addResource: vi.fn(),
}, },
}, },
], ],
@ -33,7 +33,7 @@ describe('LazyLoadService', () => {
const strategy = new ScriptLoadingStrategy('http://example.com/'); const strategy = new ScriptLoadingStrategy('http://example.com/');
afterEach(() => { afterEach(() => {
jest.clearAllMocks(); vi.clearAllMocks();
}); });
it('should create service successfully', () => { it('should create service successfully', () => {

3
npm/ng-packs/packages/core/src/lib/tests/list.service.spec.ts

@ -1,6 +1,7 @@
import { createServiceFactory, SpectatorService } from '@ngneat/spectator/jest'; import { createServiceFactory, SpectatorService } from '@ngneat/spectator/vitest';
import { of } from 'rxjs'; import { of } from 'rxjs';
import { bufferCount, take } from 'rxjs/operators'; import { bufferCount, take } from 'rxjs/operators';
import { firstValueFrom } from 'rxjs';
import { ABP } from '../models'; import { ABP } from '../models';
import { ListService, QueryStreamCreatorCallback } from '../services/list.service'; import { ListService, QueryStreamCreatorCallback } from '../services/list.service';
import { LIST_QUERY_DEBOUNCE_TIME } from '../tokens'; import { LIST_QUERY_DEBOUNCE_TIME } from '../tokens';

4
npm/ng-packs/packages/core/src/lib/tests/loading.strategy.spec.ts

@ -24,7 +24,7 @@ describe('ScriptLoadingStrategy', () => {
const domStrategy = DOM_STRATEGY.PrependToHead(); const domStrategy = DOM_STRATEGY.PrependToHead();
const crossOriginStrategy = CROSS_ORIGIN_STRATEGY.UseCredentials(); const crossOriginStrategy = CROSS_ORIGIN_STRATEGY.UseCredentials();
domStrategy.insertElement = jest.fn((el: HTMLScriptElement) => { domStrategy.insertElement = vi.fn((el: HTMLScriptElement) => {
setTimeout(() => { setTimeout(() => {
el.onload( el.onload(
new CustomEvent('success', { new CustomEvent('success', {
@ -64,7 +64,7 @@ describe('StyleLoadingStrategy', () => {
const domStrategy = DOM_STRATEGY.PrependToHead(); const domStrategy = DOM_STRATEGY.PrependToHead();
const crossOriginStrategy = CROSS_ORIGIN_STRATEGY.UseCredentials(); const crossOriginStrategy = CROSS_ORIGIN_STRATEGY.UseCredentials();
domStrategy.insertElement = jest.fn((el: HTMLLinkElement) => { domStrategy.insertElement = vi.fn((el: HTMLLinkElement) => {
setTimeout(() => { setTimeout(() => {
el.onload( el.onload(
new CustomEvent('success', { new CustomEvent('success', {

12
npm/ng-packs/packages/core/src/lib/tests/local-storage.service.spec.ts

@ -15,37 +15,37 @@ describe('LocalStorageService', () => {
}); });
it('should be called getItem', () => { it('should be called getItem', () => {
const spy = jest.spyOn(service, 'getItem'); const spy = vi.spyOn(service, 'getItem');
service.getItem('test'); service.getItem('test');
expect(spy).toHaveBeenCalled(); expect(spy).toHaveBeenCalled();
}); });
it('should be called setItem', () => { it('should be called setItem', () => {
const spy = jest.spyOn(service, 'setItem'); const spy = vi.spyOn(service, 'setItem');
service.setItem('test', 'value'); service.setItem('test', 'value');
expect(spy).toHaveBeenCalled(); expect(spy).toHaveBeenCalled();
}); });
it('should be called removeItem', () => { it('should be called removeItem', () => {
const spy = jest.spyOn(service, 'removeItem'); const spy = vi.spyOn(service, 'removeItem');
service.removeItem('test'); service.removeItem('test');
expect(spy).toHaveBeenCalled(); expect(spy).toHaveBeenCalled();
}); });
it('should be called clear', () => { it('should be called clear', () => {
const spy = jest.spyOn(service, 'clear'); const spy = vi.spyOn(service, 'clear');
service.clear(); service.clear();
expect(spy).toHaveBeenCalled(); expect(spy).toHaveBeenCalled();
}); });
it('should be called key', () => { it('should be called key', () => {
const spy = jest.spyOn(service, 'key'); const spy = vi.spyOn(service, 'key');
service.key(0); service.key(0);
expect(spy).toHaveBeenCalled(); expect(spy).toHaveBeenCalled();
}); });
it('should be called length', () => { it('should be called length', () => {
const spy = jest.spyOn(service, 'length', 'get'); const spy = vi.spyOn(service, 'length', 'get');
service.length; service.length;
expect(spy).toHaveBeenCalled(); expect(spy).toHaveBeenCalled();
}); });

4
npm/ng-packs/packages/core/src/lib/tests/localization.pipe.spec.ts

@ -1,4 +1,4 @@
import { createServiceFactory, SpectatorService, SpyObject } from '@ngneat/spectator/jest'; import { createServiceFactory, SpectatorService, SpyObject } from '@ngneat/spectator/vitest';
import { LocalizationPipe } from '../pipes/localization.pipe'; import { LocalizationPipe } from '../pipes/localization.pipe';
import { LocalizationService } from '../services/localization.service'; import { LocalizationService } from '../services/localization.service';
@ -19,7 +19,7 @@ describe('LocalizationPipe', () => {
}); });
it('should call getLocalization selector', () => { it('should call getLocalization selector', () => {
const translateSpy = jest.spyOn(localizationService, 'instant'); const translateSpy = vi.spyOn(localizationService, 'instant');
pipe.transform('test', '1', '2'); pipe.transform('test', '1', '2');
pipe.transform('test2', ['3', '4'] as any); pipe.transform('test2', ['3', '4'] as any);

22
npm/ng-packs/packages/core/src/lib/tests/localization.service.spec.ts

@ -1,4 +1,4 @@
import { createServiceFactory, SpectatorService } from '@ngneat/spectator/jest'; import { createServiceFactory, SpectatorService } from '@ngneat/spectator/vitest';
import { Subject } from 'rxjs'; import { Subject } from 'rxjs';
import { LocalizationService } from '../services/localization.service'; import { LocalizationService } from '../services/localization.service';
import { SessionStateService } from '../services/session-state.service'; import { SessionStateService } from '../services/session-state.service';
@ -18,26 +18,26 @@ describe('LocalizationService', () => {
{ {
provide: SessionStateService, provide: SessionStateService,
useValue: { useValue: {
getLanguage: jest.fn(() => 'en'), getLanguage: vi.fn(() => 'en'),
setLanguage: jest.fn(), setLanguage: vi.fn(),
getLanguage$: jest.fn(() => new Subject()), getLanguage$: vi.fn(() => new Subject()),
onLanguageChange$: jest.fn(() => new Subject()), onLanguageChange$: vi.fn(() => new Subject()),
}, },
}, },
{ {
provide: ConfigStateService, provide: ConfigStateService,
useValue: { useValue: {
getOne: jest.fn(), getOne: vi.fn(),
refreshAppState: jest.fn(), refreshAppState: vi.fn(),
getDeep: jest.fn(), getDeep: vi.fn(),
getDeep$: jest.fn(() => new Subject()), getDeep$: vi.fn(() => new Subject()),
getOne$: jest.fn(() => new Subject()), getOne$: vi.fn(() => new Subject()),
}, },
}, },
{ {
provide: Injector, provide: Injector,
useValue: { useValue: {
get: jest.fn(), get: vi.fn(),
}, },
}, },
], ],

8
npm/ng-packs/packages/core/src/lib/tests/multi-tenancy-utils.spec.ts

@ -1,5 +1,5 @@
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import { createComponentFactory, Spectator } from '@ngneat/spectator/jest'; import { createComponentFactory, Spectator } from '@ngneat/spectator/vitest';
import clone from 'just-clone'; import clone from 'just-clone';
import { of } from 'rxjs'; import { of } from 'rxjs';
@ -68,9 +68,9 @@ describe('MultiTenancyUtils', () => {
test('should get the tenancyName, set replaced environment and call the findTenantByName method of AbpTenantService', async () => { test('should get the tenancyName, set replaced environment and call the findTenantByName method of AbpTenantService', async () => {
const environmentService = spectator.inject(EnvironmentService); const environmentService = spectator.inject(EnvironmentService);
const multiTenancyService = spectator.inject(MultiTenancyService); const multiTenancyService = spectator.inject(MultiTenancyService);
const setTenantByName = jest.spyOn(multiTenancyService, 'setTenantByName'); const setTenantByName = vi.spyOn(multiTenancyService, 'setTenantByName');
const getEnvironmentSpy = jest.spyOn(environmentService, 'getEnvironment'); const getEnvironmentSpy = vi.spyOn(environmentService, 'getEnvironment');
const setStateSpy = jest.spyOn(environmentService, 'setState'); const setStateSpy = vi.spyOn(environmentService, 'setState');
getEnvironmentSpy.mockReturnValue(clone(environment)); getEnvironmentSpy.mockReturnValue(clone(environment));

6
npm/ng-packs/packages/core/src/lib/tests/permission.directive.spec.ts

@ -1,4 +1,4 @@
import { createDirectiveFactory, SpectatorDirective } from '@ngneat/spectator/jest'; import { createDirectiveFactory, SpectatorDirective } from '@ngneat/spectator/vitest';
import { Subject } from 'rxjs'; import { Subject } from 'rxjs';
import { PermissionDirective } from '../directives/permission.directive'; import { PermissionDirective } from '../directives/permission.directive';
import { PermissionService } from '../services/permission.service'; import { PermissionService } from '../services/permission.service';
@ -13,8 +13,8 @@ describe('PermissionDirective', () => {
directive: PermissionDirective, directive: PermissionDirective,
providers: [ providers: [
{ provide: PermissionService, useValue: { getGrantedPolicy$: () => grantedPolicy$ } }, { provide: PermissionService, useValue: { getGrantedPolicy$: () => grantedPolicy$ } },
{ provide: QUEUE_MANAGER, useValue: { add: jest.fn() } }, { provide: QUEUE_MANAGER, useValue: { add: vi.fn() } },
{ provide: ChangeDetectorRef, useValue: { detectChanges: jest.fn() } }, { provide: ChangeDetectorRef, useValue: { detectChanges: vi.fn() } },
], ],
}); });

10
npm/ng-packs/packages/core/src/lib/tests/replaceable-template.directive.spec.ts

@ -1,6 +1,6 @@
import { Component, EventEmitter, Input, Output, inject } from '@angular/core'; import { Component, EventEmitter, Input, Output, inject } from '@angular/core';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { createDirectiveFactory, SpectatorDirective } from '@ngneat/spectator/jest'; import { createDirectiveFactory, SpectatorDirective } from '@ngneat/spectator/vitest';
import { BehaviorSubject } from 'rxjs'; import { BehaviorSubject } from 'rxjs';
import { ReplaceableTemplateDirective } from '../directives/replaceable-template.directive'; import { ReplaceableTemplateDirective } from '../directives/replaceable-template.directive';
import { ReplaceableComponents } from '../models/replaceable-components'; import { ReplaceableComponents } from '../models/replaceable-components';
@ -50,8 +50,8 @@ describe('ReplaceableTemplateDirective', () => {
}); });
describe('without external component', () => { describe('without external component', () => {
const twoWayChange = jest.fn(a => a); const twoWayChange = vi.fn(a => a);
const someOutput = jest.fn(a => a); const someOutput = vi.fn(a => a);
beforeEach(() => { beforeEach(() => {
spectator = createDirective( spectator = createDirective(
@ -88,8 +88,8 @@ describe('ReplaceableTemplateDirective', () => {
hostProps: { hostProps: {
oneWay: { label: 'Test' }, oneWay: { label: 'Test' },
twoWay: false, twoWay: false,
twoWayChange: jest.fn(), twoWayChange: vi.fn(),
someOutput: jest.fn(), someOutput: vi.fn(),
}, },
}, },
); );

9
npm/ng-packs/packages/core/src/lib/tests/rest.service.spec.ts

@ -1,7 +1,8 @@
import { createHttpFactory, HttpMethod, SpectatorHttp, SpyObject } from '@ngneat/spectator/jest'; import { createHttpFactory, HttpMethod, SpectatorHttp, SpyObject } from '@ngneat/spectator/vitest';
import { OAuthService } from 'angular-oauth2-oidc'; import { OAuthService } from 'angular-oauth2-oidc';
import { of, throwError } from 'rxjs'; import { of, throwError } from 'rxjs';
import { catchError } from 'rxjs/operators'; import { catchError } from 'rxjs/operators';
import { firstValueFrom } from 'rxjs';
import { Rest } from '../models/rest'; import { Rest } from '../models/rest';
import { EnvironmentService } from '../services/environment.service'; import { EnvironmentService } from '../services/environment.service';
import { HttpErrorReporterService } from '../services/http-error-reporter.service'; import { HttpErrorReporterService } from '../services/http-error-reporter.service';
@ -75,7 +76,7 @@ describe('HttpClient testing', () => {
}); });
test('should complete upon successful request', done => { test('should complete upon successful request', done => {
const complete = jest.fn(done); const complete = vi.fn(done);
spectator.service.request({ method: HttpMethod.GET, url: '/test' }).subscribe({ complete }); spectator.service.request({ method: HttpMethod.GET, url: '/test' }).subscribe({ complete });
@ -84,7 +85,7 @@ describe('HttpClient testing', () => {
}); });
test('should handle the error', () => { test('should handle the error', () => {
const spy = jest.spyOn(httpErrorReporter, 'reportError'); const spy = vi.spyOn(httpErrorReporter, 'reportError');
spectator.service spectator.service
.request({ method: HttpMethod.GET, url: '/test' }, { observe: Rest.Observe.Events }) .request({ method: HttpMethod.GET, url: '/test' }, { observe: Rest.Observe.Events })
@ -102,7 +103,7 @@ describe('HttpClient testing', () => {
}); });
test('should not handle the error when skipHandleError is true', () => { test('should not handle the error when skipHandleError is true', () => {
const spy = jest.spyOn(httpErrorReporter, 'reportError'); const spy = vi.spyOn(httpErrorReporter, 'reportError');
spectator.service spectator.service
.request( .request(

4
npm/ng-packs/packages/core/src/lib/tests/route-utils.spec.ts

@ -1,6 +1,6 @@
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import { RouterModule } from '@angular/router'; import { RouterModule } from '@angular/router';
import { createRoutingFactory, SpectatorRouting } from '@ngneat/spectator/jest'; import { createRoutingFactory, SpectatorRouting } from '@ngneat/spectator/vitest';
import { RouterOutletComponent } from '../components/router-outlet.component'; import { RouterOutletComponent } from '../components/router-outlet.component';
import { RoutesService } from '../services/routes.service'; import { RoutesService } from '../services/routes.service';
import { findRoute, getRoutePath } from '../utils/route-utils'; import { findRoute, getRoutePath } from '../utils/route-utils';
@ -23,7 +23,7 @@ describe('Route Utils', () => {
`( `(
'should find $expected in $count turns when path is $path', 'should find $expected in $count turns when path is $path',
async ({ path, expected, count }) => { async ({ path, expected, count }) => {
const find = jest.fn(cb => (cb(node) ? node : null)); const find = vi.fn(cb => (cb(node) ? node : null));
const routes = { find } as any as RoutesService; const routes = { find } as any as RoutesService;
const route = findRoute(routes, path); const route = findRoute(routes, path);
expect(route).toBe(expected); expect(route).toBe(expected);

2
npm/ng-packs/packages/core/src/lib/tests/router-events.service.spec.ts

@ -1,6 +1,6 @@
import { Router, RouterEvent, NavigationStart, ResolveStart, NavigationError, NavigationEnd, ResolveEnd, NavigationCancel } from '@angular/router'; import { Router, RouterEvent, NavigationStart, ResolveStart, NavigationError, NavigationEnd, ResolveEnd, NavigationCancel } from '@angular/router';
import { Subject } from 'rxjs'; import { Subject } from 'rxjs';
import { createServiceFactory, SpectatorService } from '@ngneat/spectator/jest'; import { createServiceFactory, SpectatorService } from '@ngneat/spectator/vitest';
import { take } from 'rxjs/operators'; import { take } from 'rxjs/operators';
import { NavigationEventKey, RouterEvents } from '../services/router-events.service'; import { NavigationEventKey, RouterEvents } from '../services/router-events.service';

2
npm/ng-packs/packages/core/src/lib/tests/router-outlet.component.spec.ts

@ -1,4 +1,4 @@
import { Spectator, createComponentFactory } from '@ngneat/spectator/jest'; import { Spectator, createComponentFactory } from '@ngneat/spectator/vitest';
import { provideRouter } from '@angular/router'; import { provideRouter } from '@angular/router';
import { RouterOutletComponent } from '../components/router-outlet.component'; import { RouterOutletComponent } from '../components/router-outlet.component';

4
npm/ng-packs/packages/core/src/lib/tests/routes.handler.spec.ts

@ -1,7 +1,7 @@
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { RoutesHandler } from '../handlers/routes.handler'; import { RoutesHandler } from '../handlers/routes.handler';
import { RoutesService } from '../services/routes.service'; import { RoutesService } from '../services/routes.service';
import { createServiceFactory, SpectatorService } from '@ngneat/spectator/jest'; import { createServiceFactory, SpectatorService } from '@ngneat/spectator/vitest';
describe('Routes Handler', () => { describe('Routes Handler', () => {
let spectator: SpectatorService<RoutesHandler>; let spectator: SpectatorService<RoutesHandler>;
@ -15,7 +15,7 @@ describe('Routes Handler', () => {
{ {
provide: RoutesService, provide: RoutesService,
useValue: { useValue: {
add: jest.fn(), add: vi.fn(),
}, },
}, },
{ {

30
npm/ng-packs/packages/core/src/lib/tests/routes.service.spec.ts

@ -1,5 +1,5 @@
import { RoutesService } from '../services/routes.service'; import { RoutesService } from '../services/routes.service';
import { createServiceFactory, SpectatorService } from '@ngneat/spectator/jest'; import { createServiceFactory, SpectatorService } from '@ngneat/spectator/vitest';
import { CORE_OPTIONS } from '../tokens/options.token'; import { CORE_OPTIONS } from '../tokens/options.token';
import { HttpClient } from '@angular/common/http'; import { HttpClient } from '@angular/common/http';
import { ConfigStateService } from '../services/config-state.service'; import { ConfigStateService } from '../services/config-state.service';
@ -33,51 +33,51 @@ describe('Routes Service', () => {
{ {
provide: HttpClient, provide: HttpClient,
useValue: { useValue: {
get: jest.fn(), get: vi.fn(),
post: jest.fn(), post: vi.fn(),
put: jest.fn(), put: vi.fn(),
delete: jest.fn(), delete: vi.fn(),
}, },
}, },
{ {
provide: ConfigStateService, provide: ConfigStateService,
useValue: { useValue: {
getOne: jest.fn(), getOne: vi.fn(),
getDeep: jest.fn(), getDeep: vi.fn(),
getDeep$: jest.fn(() => ({ subscribe: jest.fn() })), getDeep$: vi.fn(() => ({ subscribe: vi.fn() })),
createOnUpdateStream: jest.fn(() => ({ createOnUpdateStream: vi.fn(() => ({
subscribe: jest.fn(() => ({ unsubscribe: jest.fn() })) subscribe: vi.fn(() => ({ unsubscribe: vi.fn() }))
})), })),
}, },
}, },
{ {
provide: AbpApplicationConfigurationService, provide: AbpApplicationConfigurationService,
useValue: { useValue: {
get: jest.fn(), get: vi.fn(),
}, },
}, },
{ {
provide: RestService, provide: RestService,
useValue: { useValue: {
request: jest.fn(), request: vi.fn(),
}, },
}, },
{ {
provide: EnvironmentService, provide: EnvironmentService,
useValue: { useValue: {
getEnvironment: jest.fn(), getEnvironment: vi.fn(),
}, },
}, },
{ {
provide: HttpErrorReporterService, provide: HttpErrorReporterService,
useValue: { useValue: {
reportError: jest.fn(), reportError: vi.fn(),
}, },
}, },
{ {
provide: ExternalHttpClient, provide: ExternalHttpClient,
useValue: { useValue: {
request: jest.fn(), request: vi.fn(),
}, },
}, },
{ {

4
npm/ng-packs/packages/core/src/lib/tests/safe-html.pipe.spec.ts

@ -1,4 +1,4 @@
import { createServiceFactory, SpectatorService } from '@ngneat/spectator/jest'; import { createServiceFactory, SpectatorService } from '@ngneat/spectator/vitest';
import { SafeHtmlPipe } from '../pipes'; import { SafeHtmlPipe } from '../pipes';
describe('SafeHtmlPipe', () => { describe('SafeHtmlPipe', () => {
@ -27,7 +27,7 @@ describe('SafeHtmlPipe', () => {
}); });
it('should sanitize unsafe HTML content', () => { it('should sanitize unsafe HTML content', () => {
const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => undefined); const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => undefined);
const input = `<script>alert("hello world");</script><p><a href='#' onclick="alert('This is an XSS attack!')">Click here!</a></p>`; const input = `<script>alert("hello world");</script><p><a href='#' onclick="alert('This is an XSS attack!')">Click here!</a></p>`;
const result = pipe.transform(input); const result = pipe.transform(input);
expect(result).toBe(`<p><a href="#">Click here!</a></p>`); expect(result).toBe(`<p><a href="#">Click here!</a></p>`);

108
npm/ng-packs/packages/core/src/lib/tests/show-password-directive.spec.ts

@ -1,55 +1,55 @@
import { Component, DebugElement } from '@angular/core' import { Component, DebugElement } from '@angular/core'
import { ComponentFixture, TestBed } from '@angular/core/testing' import { ComponentFixture, TestBed } from '@angular/core/testing'
import { ShowPasswordDirective } from '../directives'; import { ShowPasswordDirective } from '../directives';
import { By } from '@angular/platform-browser'; import { By } from '@angular/platform-browser';
@Component({ @Component({
standalone:true, standalone:true,
template: ` template: `
<input [abpShowPassword]="true"> <input [abpShowPassword]="true">
<input [abpShowPassword]="false"> <input [abpShowPassword]="false">
<input /> <input />
<input [abpShowPassword]="showPassword" />`, <input [abpShowPassword]="showPassword" />`,
imports:[ShowPasswordDirective] imports:[ShowPasswordDirective]
}) })
class TestComponent { class TestComponent {
showPassword = false showPassword = false
} }
describe('ShowPasswordDirective',()=>{ describe('ShowPasswordDirective',()=>{
let fixture: ComponentFixture<TestComponent>;; let fixture: ComponentFixture<TestComponent>;;
let des : DebugElement[]; let des : DebugElement[];
let desAll : DebugElement[]; let desAll : DebugElement[];
let bareInput; let bareInput;
beforeEach(()=>{ beforeEach(()=>{
fixture = TestBed.configureTestingModule({ fixture = TestBed.configureTestingModule({
imports: [ TestComponent ] imports: [ TestComponent ]
}).createComponent(TestComponent) }).createComponent(TestComponent)
fixture.detectChanges(); fixture.detectChanges();
des = fixture.debugElement.queryAll(By.directive(ShowPasswordDirective)); des = fixture.debugElement.queryAll(By.directive(ShowPasswordDirective));
desAll = fixture.debugElement.queryAll(By.all()); desAll = fixture.debugElement.queryAll(By.all());
bareInput = fixture.debugElement.query(By.css('input:not([abpShowPassword])')); bareInput = fixture.debugElement.query(By.css('input:not([abpShowPassword])'));
}) })
it('should have three input has ShowPasswordDirective elements', () => { it('should have three input has ShowPasswordDirective elements', () => {
expect(des.length).toBe(3); expect(des.length).toBe(3);
}); });
test.each([[0,'text'],[1,'password'],[2,'text'],[3,'password']])('%p. input type must be %p)', (index,inpType) => { test.each([[0,'text'],[1,'password'],[2,'text'],[3,'password']])('%p. input type must be %p)', (index,inpType) => {
const inputType = desAll[index].nativeElement.type; const inputType = desAll[index].nativeElement.type;
expect(inputType).toBe(inpType); expect(inputType).toBe(inpType);
}); });
it('should have three input has ShowPasswordDirective elements', () => { it('should have three input has ShowPasswordDirective elements', () => {
const input = des[2].nativeElement const input = des[2].nativeElement
expect(input.type).toBe('password') expect(input.type).toBe('password')
fixture.componentInstance.showPassword = true fixture.componentInstance.showPassword = true
fixture.detectChanges() fixture.detectChanges()
expect(input.type).toBe('text') expect(input.type).toBe('text')
}); });
}); });

2
npm/ng-packs/packages/core/src/lib/tests/sort.pipe.spec.ts

@ -1,4 +1,4 @@
import { createServiceFactory, SpectatorService } from '@ngneat/spectator/jest'; import { createServiceFactory, SpectatorService } from '@ngneat/spectator/vitest';
import { SortPipe } from '../pipes/sort.pipe'; import { SortPipe } from '../pipes/sort.pipe';
describe('SortPipe', () => { describe('SortPipe', () => {

6
npm/ng-packs/packages/core/src/lib/tests/stop-propagation.directive.spec.ts

@ -1,12 +1,12 @@
import { createDirectiveFactory, SpectatorDirective } from '@ngneat/spectator/jest'; import { createDirectiveFactory, SpectatorDirective } from '@ngneat/spectator/vitest';
import { StopPropagationDirective } from '../directives/stop-propagation.directive'; import { StopPropagationDirective } from '../directives/stop-propagation.directive';
describe('StopPropagationDirective', () => { describe('StopPropagationDirective', () => {
let spectator: SpectatorDirective<StopPropagationDirective>; let spectator: SpectatorDirective<StopPropagationDirective>;
let directive: StopPropagationDirective; let directive: StopPropagationDirective;
let link: HTMLAnchorElement; let link: HTMLAnchorElement;
const childClickEventFn = jest.fn(() => null); const childClickEventFn = vi.fn(() => null);
const parentClickEventFn = jest.fn(() => null); const parentClickEventFn = vi.fn(() => null);
const createDirective = createDirectiveFactory({ const createDirective = createDirectiveFactory({
directive: StopPropagationDirective, directive: StopPropagationDirective,
}); });

6
npm/ng-packs/packages/core/src/lib/tests/subscription.service.spec.ts

@ -14,8 +14,8 @@ describe('SubscriptionService', () => {
describe('#addOne', () => { describe('#addOne', () => {
it('should subscribe to given observable with next and error functions and return the Subscription instance', () => { it('should subscribe to given observable with next and error functions and return the Subscription instance', () => {
const next = jest.fn(); const next = vi.fn();
const error = jest.fn(); const error = vi.fn();
const subscription = service.addOne(of(null), next, error); const subscription = service.addOne(of(null), next, error);
expect(subscription).toBeInstanceOf(Subscription); expect(subscription).toBeInstanceOf(Subscription);
expect(next).toHaveBeenCalledWith(null); expect(next).toHaveBeenCalledWith(null);
@ -24,7 +24,7 @@ describe('SubscriptionService', () => {
}); });
it('should subscribe to given observable with observer and return the Subscription instance', () => { it('should subscribe to given observable with observer and return the Subscription instance', () => {
const observer = { next: jest.fn(), complete: jest.fn() }; const observer = { next: vi.fn(), complete: vi.fn() };
const subscription = service.addOne(of(null), observer); const subscription = service.addOne(of(null), observer);
expect(subscription).toBeInstanceOf(Subscription); expect(subscription).toBeInstanceOf(Subscription);
expect(observer.next).toHaveBeenCalledWith(null); expect(observer.next).toHaveBeenCalledWith(null);

Loading…
Cancel
Save