diff --git a/npm/ng-packs/packages/core/src/lib/tests/autofocus.directive.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/autofocus.directive.spec.ts index 6a44e0d83e..a95f88217d 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/autofocus.directive.spec.ts +++ b/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 { timer } from 'rxjs'; +import { timer , firstValueFrom } from 'rxjs'; describe('AutofocusDirective', () => { let spectator: SpectatorDirective; diff --git a/npm/ng-packs/packages/core/src/lib/tests/config-state.service.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/config-state.service.spec.ts index 3067ab9536..c1e64216c6 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/config-state.service.spec.ts +++ b/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 { provideHttpClient } from '@angular/common/http'; -import { createServiceFactory, SpectatorService } from '@ngneat/spectator/jest'; +import { createServiceFactory, SpectatorService } from '@ngneat/spectator/vitest'; import { of } from 'rxjs'; import { AbpApplicationConfigurationService } from '../proxy/volo/abp/asp-net-core/mvc/application-configurations/abp-application-configuration.service'; import { @@ -142,84 +142,84 @@ describe('ConfigStateService', () => { spectator = createService(); configState = spectator.service; - jest.spyOn(configState, 'getAll').mockReturnValue(CONFIG_STATE_DATA); - jest.spyOn(configState, 'getAll$').mockReturnValue(of(CONFIG_STATE_DATA)); - jest.spyOn(configState, 'getOne').mockImplementation((key) => { + vi.spyOn(configState, 'getAll').mockReturnValue(CONFIG_STATE_DATA); + vi.spyOn(configState, 'getAll$').mockReturnValue(of(CONFIG_STATE_DATA)); + vi.spyOn(configState, 'getOne').mockImplementation((key) => { if (key === 'localization') return CONFIG_STATE_DATA.localization; return undefined; }); - jest.spyOn(configState, 'getOne$').mockImplementation((key) => { + vi.spyOn(configState, 'getOne$').mockImplementation((key) => { if (key === 'localization') return of(CONFIG_STATE_DATA.localization); 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 === 'test') 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); 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']; 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']); 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']; 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']); 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 === 'localization') return { 'Abp.Localization.DefaultLanguage': 'en' }; if (keyword === 'Localization') return { 'Abp.Localization.DefaultLanguage': 'en' }; 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 === 'localization') return of({ 'Abp.Localization.DefaultLanguage': 'en' }); if (keyword === 'Localization') return of({ 'Abp.Localization.DefaultLanguage': 'en' }); return of({}); }); - jest.spyOn(configState, 'getFeatures').mockImplementation((keys) => { + vi.spyOn(configState, 'getFeatures').mockImplementation((keys) => { if (keys.includes('Chat.Enable')) { return { 'Chat.Enable': 'True' }; } return {}; }); - jest.spyOn(configState, 'getFeatures$').mockImplementation((keys) => { + vi.spyOn(configState, 'getFeatures$').mockImplementation((keys) => { if (keys.includes('Chat.Enable')) { return of({ 'Chat.Enable': 'True' }); } return of({}); }); - jest.spyOn(configState, 'getFeatureIsEnabled').mockImplementation((key) => { + vi.spyOn(configState, 'getFeatureIsEnabled').mockImplementation((key) => { if (key === 'Chat.Enable') return true; return false; }); - jest.spyOn(configState, 'getFeatureIsEnabled$').mockImplementation((key) => { + vi.spyOn(configState, 'getFeatureIsEnabled$').mockImplementation((key) => { if (key === 'Chat.Enable') return of(true); return of(false); }); - jest.spyOn(configState, 'getGlobalFeatures').mockReturnValue({ + vi.spyOn(configState, 'getGlobalFeatures').mockReturnValue({ enabledFeatures: ['Feature1', 'Feature2'] }); - jest.spyOn(configState, 'getGlobalFeatures$').mockReturnValue(of({ + vi.spyOn(configState, 'getGlobalFeatures$').mockReturnValue(of({ enabledFeatures: ['Feature1', 'Feature2'] })); - jest.spyOn(configState, 'getGlobalFeatureIsEnabled').mockImplementation((key) => { + vi.spyOn(configState, 'getGlobalFeatureIsEnabled').mockImplementation((key) => { if (key === 'Feature1') return true; return false; }); - jest.spyOn(configState, 'getGlobalFeatureIsEnabled$').mockImplementation((key) => { + vi.spyOn(configState, 'getGlobalFeatureIsEnabled$').mockImplementation((key) => { if (key === 'Feature1') return of(true); return of(false); }); diff --git a/npm/ng-packs/packages/core/src/lib/tests/container.strategy.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/container.strategy.spec.ts index 061cba5bd1..28b2743bd1 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/container.strategy.spec.ts +++ b/npm/ng-packs/packages/core/src/lib/tests/container.strategy.spec.ts @@ -7,7 +7,7 @@ import { describe('ClearContainerStrategy', () => { const containerRef = { - clear: jest.fn(), + clear: vi.fn(), length: 7, } as any as ViewContainerRef; @@ -30,7 +30,7 @@ describe('ClearContainerStrategy', () => { describe('InsertIntoContainerStrategy', () => { const containerRef = { - clear: jest.fn(), + clear: vi.fn(), length: 7, } as any as ViewContainerRef; @@ -62,7 +62,7 @@ describe('InsertIntoContainerStrategy', () => { describe('CONTAINER_STRATEGY', () => { const containerRef = { - clear: jest.fn(), + clear: vi.fn(), length: 7, } as any as ViewContainerRef; diff --git a/npm/ng-packs/packages/core/src/lib/tests/content-projection.service.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/content-projection.service.spec.ts index fc5112a5bb..8631e7868d 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/content-projection.service.spec.ts +++ b/npm/ng-packs/packages/core/src/lib/tests/content-projection.service.spec.ts @@ -1,5 +1,5 @@ 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 { PROJECTION_STRATEGY } from '../strategies'; diff --git a/npm/ng-packs/packages/core/src/lib/tests/content.strategy.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/content.strategy.spec.ts index e1a5ceb86e..fe8750dfc8 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/content.strategy.spec.ts +++ b/npm/ng-packs/packages/core/src/lib/tests/content.strategy.spec.ts @@ -22,8 +22,8 @@ describe('StyleContentStrategy', () => { const domStrategy = DOM_STRATEGY.PrependToHead(); const contentSecurityStrategy = CONTENT_SECURITY_STRATEGY.None(); - contentSecurityStrategy.applyCSP = jest.fn((el: HTMLScriptElement) => {}); - domStrategy.insertElement = jest.fn((el: HTMLScriptElement) => {}) as any; + contentSecurityStrategy.applyCSP = vi.fn((el: HTMLScriptElement) => {}); + domStrategy.insertElement = vi.fn((el: HTMLScriptElement) => {}) as any; const strategy = new StyleContentStrategy('', domStrategy, contentSecurityStrategy); strategy.createElement(); @@ -53,8 +53,8 @@ describe('ScriptContentStrategy', () => { const domStrategy = DOM_STRATEGY.PrependToHead(); const contentSecurityStrategy = CONTENT_SECURITY_STRATEGY.Loose(nonce); - contentSecurityStrategy.applyCSP = jest.fn((el: HTMLScriptElement) => {}); - domStrategy.insertElement = jest.fn((el: HTMLScriptElement) => {}) as any; + contentSecurityStrategy.applyCSP = vi.fn((el: HTMLScriptElement) => {}); + domStrategy.insertElement = vi.fn((el: HTMLScriptElement) => {}) as any; const strategy = new ScriptContentStrategy('', domStrategy, contentSecurityStrategy); const element = strategy.createElement(); diff --git a/npm/ng-packs/packages/core/src/lib/tests/context.strategy.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/context.strategy.spec.ts index 461c397457..360f09e484 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/context.strategy.spec.ts +++ b/npm/ng-packs/packages/core/src/lib/tests/context.strategy.spec.ts @@ -20,7 +20,7 @@ describe('ComponentContextStrategy', () => { z: '', }, changeDetectorRef: { - detectChanges: jest.fn(), + detectChanges: vi.fn(), }, } as any), ); diff --git a/npm/ng-packs/packages/core/src/lib/tests/date-utils.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/date-utils.spec.ts index 9359a425d7..67143de87a 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/date-utils.spec.ts +++ b/npm/ng-packs/packages/core/src/lib/tests/date-utils.spec.ts @@ -1,6 +1,6 @@ import { ConfigStateService } from '../services'; 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 { HttpClient } from '@angular/common/http'; 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, useValue: { - get: jest.fn(), - post: jest.fn(), - put: jest.fn(), - delete: jest.fn(), + get: vi.fn(), + post: vi.fn(), + put: vi.fn(), + delete: vi.fn(), }, }, { provide: AbpApplicationConfigurationService, useValue: { - get: jest.fn(), + get: vi.fn(), }, }, { provide: RestService, useValue: { - request: jest.fn(), + request: vi.fn(), }, }, { provide: EnvironmentService, useValue: { - getEnvironment: jest.fn(), + getEnvironment: vi.fn(), }, }, { provide: HttpErrorReporterService, useValue: { - reportError: jest.fn(), + reportError: vi.fn(), }, }, { provide: ExternalHttpClient, useValue: { - request: jest.fn(), + request: vi.fn(), }, }, ], @@ -87,7 +87,7 @@ describe('Date Utils', () => { describe('#getShortDateFormat', () => { 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); expect(getShortDateFormat(config)).toBe('M/d/yyyy'); @@ -97,7 +97,7 @@ describe('Date Utils', () => { describe('#getShortTimeFormat', () => { 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); expect(getShortTimeFormat(config)).toBe('h:mm a'); @@ -107,7 +107,7 @@ describe('Date Utils', () => { describe('#getShortDateShortTimeFormat', () => { 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); expect(getShortDateShortTimeFormat(config)).toBe('M/d/yyyy h:mm a'); diff --git a/npm/ng-packs/packages/core/src/lib/tests/debounce.directive.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/debounce.directive.spec.ts index 0cf931dd61..81d27b0cf9 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/debounce.directive.spec.ts +++ b/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 { timer } from 'rxjs'; +import { timer , firstValueFrom } from 'rxjs'; describe('InputEventDebounceDirective', () => { let spectator: SpectatorDirective; let directive: InputEventDebounceDirective; let input: HTMLInputElement; - const inputEventFn = jest.fn(() => {}); + const inputEventFn = vi.fn(() => {}); const createDirective = createDirectiveFactory({ directive: InputEventDebounceDirective, diff --git a/npm/ng-packs/packages/core/src/lib/tests/dynamic-layout.component.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/dynamic-layout.component.spec.ts index 92a08eff2c..524b767799 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/dynamic-layout.component.spec.ts +++ b/npm/ng-packs/packages/core/src/lib/tests/dynamic-layout.component.spec.ts @@ -1,7 +1,7 @@ import { HttpClient } from '@angular/common/http'; import { Component, NgModule, inject as inject_1 } from '@angular/core'; 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 { eLayoutType } from '../enums/common'; import { ABP } from '../models'; @@ -74,10 +74,10 @@ describe('DynamicLayoutComponent', () => { { provide: RoutesService, useValue: { - add: jest.fn(), - flat$: { pipe: jest.fn() }, - tree$: { pipe: jest.fn() }, - visible$: { pipe: jest.fn() }, + add: vi.fn(), + flat$: { pipe: vi.fn() }, + tree$: { pipe: vi.fn() }, + visible$: { pipe: vi.fn() }, }, }, ReplaceableComponentsService, diff --git a/npm/ng-packs/packages/core/src/lib/tests/environment-utils.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/environment-utils.spec.ts index 66fbf7b29b..bc1af8e5f4 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/environment-utils.spec.ts +++ b/npm/ng-packs/packages/core/src/lib/tests/environment-utils.spec.ts @@ -1,6 +1,6 @@ import { HttpClient } from '@angular/common/http'; 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 { Environment, RemoteEnv } from '../models/environment'; import { EnvironmentService } from '../services/environment.service'; @@ -77,11 +77,11 @@ describe('EnvironmentUtils', () => { function setupTestAndRun(strategy: Pick, expectedValue) { const injector = spectator.inject(Injector); - const injectorSpy = jest.spyOn(injector, 'get'); + const injectorSpy = vi.spyOn(injector, 'get'); const http = spectator.inject(HttpClient); - const requestSpy = jest.spyOn(http, 'request'); + const requestSpy = vi.spyOn(http, 'request'); const environmentService = spectator.inject(EnvironmentService); - const setStateSpy = jest.spyOn(environmentService, 'setState'); + const setStateSpy = vi.spyOn(environmentService, 'setState'); injectorSpy.mockReturnValueOnce(environmentService); injectorSpy.mockReturnValueOnce(http); diff --git a/npm/ng-packs/packages/core/src/lib/tests/form-submit.directive.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/form-submit.directive.spec.ts index 094a41d4a6..0a27adaab9 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/form-submit.directive.spec.ts +++ b/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 { FormsModule, ReactiveFormsModule, FormGroup } from '@angular/forms'; -import { timer } from 'rxjs'; +import { timer , firstValueFrom } from 'rxjs'; describe('FormSubmitDirective', () => { let spectator: SpectatorDirective; let directive: FormSubmitDirective; const formGroup = new FormGroup({}); - const submitEventFn = jest.fn(() => {}); + const submitEventFn = vi.fn(() => {}); const createDirective = createDirectiveFactory({ directive: FormSubmitDirective, diff --git a/npm/ng-packs/packages/core/src/lib/tests/internal-store.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/internal-store.spec.ts index 011a777e4a..7a42016eea 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/internal-store.spec.ts +++ b/npm/ng-packs/packages/core/src/lib/tests/internal-store.spec.ts @@ -1,5 +1,6 @@ import clone from 'just-clone'; import { take } from 'rxjs/operators'; +import { firstValueFrom } from 'rxjs'; import { DeepPartial } from '../models/utility'; import { InternalStore } from '../utils/internal-store-utils'; @@ -124,18 +125,20 @@ describe('Internal Store', () => { }); 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 onQux$ = store.sliceUpdate(state => state.foo.bar.qux); - onQux$.pipe(take(1)).subscribe(value => { - expect(value).toEqual(deepPatch2.foo.bar.qux); - done(); - }); + return new Promise(resolve => { + onQux$.pipe(take(1)).subscribe(value => { + expect(value).toEqual(deepPatch2.foo.bar.qux); + resolve(); + }); - store.deepPatch(deepPatch1); - store.deepPatch(deepPatch2); + store.deepPatch(deepPatch1); + store.deepPatch(deepPatch2); + }); }); }); diff --git a/npm/ng-packs/packages/core/src/lib/tests/internet-connection.service.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/internet-connection.service.spec.ts index b4809471eb..08f7e48c37 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/internet-connection.service.spec.ts +++ b/npm/ng-packs/packages/core/src/lib/tests/internet-connection.service.spec.ts @@ -1,100 +1,100 @@ -import { TestBed} from '@angular/core/testing'; -import { DOCUMENT } from '@angular/common'; - -import { InternetConnectionService } from '../services/internet-connection-service'; -import { first } from 'rxjs'; - -let service: InternetConnectionService; - -describe('Internet connection when disconnected', () => { - const events = {}; - const addEventListener = jest.fn((event, callback) => { - events[event] = callback; - }); - const mockDocument = { defaultView: {navigator: {onLine: false}, addEventListener } } - beforeAll(() => { - TestBed.configureTestingModule({ - providers:[{provide:DOCUMENT, useValue: mockDocument}] - }) - service = TestBed.inject(InternetConnectionService); - }); - - it('document should be created', () => { - expect(service.document).toEqual(mockDocument); - }); - - it('signal value should be false', () => { - expect(service.networkStatus()).toEqual(false); - }); - - it('observable value should be false', - (done: any) => { - service.networkStatus$.pipe(first()).subscribe(value => { - expect(value).toBe(false) - done(); - }); - }); - - test.each(['offline','online'])('should addEventListener for %p, event',(v)=>{ - expect(events[v]).toBeTruthy() - }) - - test.each([['offline',false],["online",true]])('when %p called ,then signal value must be %p',(eventName,value)=>{ - events[eventName]() - expect(service.networkStatus()).toEqual(value); - }) - - test.each([['offline',false],["online",true]])('when %p called,then observable must return %p',(eventName,value)=>{ - events[eventName]() - service.networkStatus$.subscribe(val=>{ - expect(val).toEqual(value) - }) - }) -}); - -describe('when connection value changes for signals', () => { - const events = {}; - const addEventListener = jest.fn((event, callback) => { - events[event] = callback; - }); - const mockDocument = { defaultView: {navigator: {onLine: false}, addEventListener } } - beforeAll(() => { - TestBed.configureTestingModule({ - providers:[{provide:DOCUMENT, useValue: mockDocument}] - }) - service = TestBed.inject(InternetConnectionService); - }); - - it('signal value must be false when offline event is called while internet is connected', () => { - events['online']() - expect(service.networkStatus()).toEqual(true); - events['offline']() - expect(service.networkStatus()).toEqual(false); - }); - - it('signal value must be true when online event is called while internet is disconnected', () => { - events['offline']() - expect(service.networkStatus()).toEqual(false); - events['online']() - expect(service.networkStatus()).toEqual(true); - }); - - it('observable value must be false when offline event is called while internet is connected', (done:any) => { - events['online']() - events['offline']() - service.networkStatus$.subscribe(val=>{ - expect(val).toEqual(false) - done() - }) - }); - - it('observable value must be true when online event is called while internet is disconnected', (done:any) => { - events['offline']() - events['online']() - service.networkStatus$.subscribe(val=>{ - console.log(val); - expect(val).toEqual(true) - done() - }) - }); +import { TestBed} from '@angular/core/testing'; +import { DOCUMENT } from '@angular/common'; + +import { InternetConnectionService } from '../services/internet-connection-service'; +import { first , firstValueFrom } from 'rxjs'; + +let service: InternetConnectionService; + +describe('Internet connection when disconnected', () => { + const events = {}; + const addEventListener = vi.fn((event, callback) => { + events[event] = callback; + }); + const mockDocument = { defaultView: {navigator: {onLine: false}, addEventListener } } + beforeAll(() => { + TestBed.configureTestingModule({ + providers:[{provide:DOCUMENT, useValue: mockDocument}] + }) + service = TestBed.inject(InternetConnectionService); + }); + + it('document should be created', () => { + expect(service.document).toEqual(mockDocument); + }); + + it('signal value should be false', () => { + expect(service.networkStatus()).toEqual(false); + }); + + it('observable value should be false', + (done: any) => { + service.networkStatus$.pipe(first()).subscribe(value => { + expect(value).toBe(false) + done(); + }); + }); + + test.each(['offline','online'])('should addEventListener for %p, event',(v)=>{ + expect(events[v]).toBeTruthy() + }) + + test.each([['offline',false],["online",true]])('when %p called ,then signal value must be %p',(eventName,value)=>{ + events[eventName]() + expect(service.networkStatus()).toEqual(value); + }) + + test.each([['offline',false],["online",true]])('when %p called,then observable must return %p',(eventName,value)=>{ + events[eventName]() + service.networkStatus$.subscribe(val=>{ + expect(val).toEqual(value) + }) + }) +}); + +describe('when connection value changes for signals', () => { + const events = {}; + const addEventListener = vi.fn((event, callback) => { + events[event] = callback; + }); + const mockDocument = { defaultView: {navigator: {onLine: false}, addEventListener } } + beforeAll(() => { + TestBed.configureTestingModule({ + providers:[{provide:DOCUMENT, useValue: mockDocument}] + }) + service = TestBed.inject(InternetConnectionService); + }); + + it('signal value must be false when offline event is called while internet is connected', () => { + events['online']() + expect(service.networkStatus()).toEqual(true); + events['offline']() + expect(service.networkStatus()).toEqual(false); + }); + + it('signal value must be true when online event is called while internet is disconnected', () => { + events['offline']() + expect(service.networkStatus()).toEqual(false); + events['online']() + expect(service.networkStatus()).toEqual(true); + }); + + it('observable value must be false when offline event is called while internet is connected', (done:any) => { + events['online']() + events['offline']() + service.networkStatus$.subscribe(val=>{ + expect(val).toEqual(false) + done() + }) + }); + + it('observable value must be true when online event is called while internet is disconnected', (done:any) => { + events['offline']() + events['online']() + service.networkStatus$.subscribe(val=>{ + console.log(val); + expect(val).toEqual(true) + done() + }) + }); }); \ No newline at end of file diff --git a/npm/ng-packs/packages/core/src/lib/tests/lazy-load-utils.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/lazy-load-utils.spec.ts index 487c157cf9..31c7618cda 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/lazy-load-utils.spec.ts +++ b/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('#fromLazyLoad', () => { afterEach(() => { - jest.clearAllMocks(); + vi.clearAllMocks(); }); it('should append to head by default', () => { const element = document.createElement('link'); - const spy = jest.spyOn(document.head, 'insertAdjacentElement'); + const spy = vi.spyOn(document.head, 'insertAdjacentElement'); fromLazyLoad(element); expect(spy).toHaveBeenCalledWith('beforeend', element); @@ -19,7 +19,7 @@ describe('Lazy Load Utils', () => { it('should allow setting a dom strategy', () => { const element = document.createElement('link'); - const spy = jest.spyOn(document.head, 'insertAdjacentElement'); + const spy = vi.spyOn(document.head, 'insertAdjacentElement'); fromLazyLoad(element, DOM_STRATEGY.PrependToHead()); expect(spy).toHaveBeenCalledWith('afterbegin', element); @@ -52,61 +52,73 @@ describe('Lazy Load Utils', () => { 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 parentNode = { removeChild: jest.fn() }; + const parentNode = { removeChild: vi.fn() }; const element = { parentNode } as any as HTMLLinkElement; - fromLazyLoad( - element, - { - insertElement(el: HTMLLinkElement) { - expect(el).toBe(element); - - setTimeout(() => { - el.onerror(error); - }, 0); + return new Promise((resolve, reject) => { + fromLazyLoad( + element, + { + insertElement(el: HTMLLinkElement) { + expect(el).toBe(element); + + setTimeout(() => { + 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 parentNode = { removeChild: jest.fn() }; + const parentNode = { removeChild: vi.fn() }; const element = { parentNode } as any as HTMLLinkElement; - fromLazyLoad( - element, - { - insertElement(el: HTMLLinkElement) { - expect(el).toBe(element); - - setTimeout(() => { - el.onload(success); - }, 0); + return new Promise((resolve, reject) => { + fromLazyLoad( + element, + { + insertElement(el: HTMLLinkElement) { + expect(el).toBe(element); + + setTimeout(() => { + 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(); - }, + }); }); }); }); diff --git a/npm/ng-packs/packages/core/src/lib/tests/lazy-load.service.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/lazy-load.service.spec.ts index 83f29ed74e..5d5292666b 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/lazy-load.service.spec.ts +++ b/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 { ScriptLoadingStrategy } from '../strategies/loading.strategy'; import { ResourceWaitService } from '../services/resource-wait.service'; -import { createServiceFactory, SpectatorService } from '@ngneat/spectator/jest'; +import { createServiceFactory, SpectatorService } from '@ngneat/spectator/vitest'; describe('LazyLoadService', () => { let spectator: SpectatorService; @@ -16,8 +16,8 @@ describe('LazyLoadService', () => { { provide: ResourceWaitService, useValue: { - wait: jest.fn(), - addResource: jest.fn(), + wait: vi.fn(), + addResource: vi.fn(), }, }, ], @@ -33,7 +33,7 @@ describe('LazyLoadService', () => { const strategy = new ScriptLoadingStrategy('http://example.com/'); afterEach(() => { - jest.clearAllMocks(); + vi.clearAllMocks(); }); it('should create service successfully', () => { diff --git a/npm/ng-packs/packages/core/src/lib/tests/list.service.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/list.service.spec.ts index d81091b2f7..a288a20bd1 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/list.service.spec.ts +++ b/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 { bufferCount, take } from 'rxjs/operators'; +import { firstValueFrom } from 'rxjs'; import { ABP } from '../models'; import { ListService, QueryStreamCreatorCallback } from '../services/list.service'; import { LIST_QUERY_DEBOUNCE_TIME } from '../tokens'; diff --git a/npm/ng-packs/packages/core/src/lib/tests/loading.strategy.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/loading.strategy.spec.ts index cb1fc52ede..492aaf7f66 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/loading.strategy.spec.ts +++ b/npm/ng-packs/packages/core/src/lib/tests/loading.strategy.spec.ts @@ -24,7 +24,7 @@ describe('ScriptLoadingStrategy', () => { const domStrategy = DOM_STRATEGY.PrependToHead(); const crossOriginStrategy = CROSS_ORIGIN_STRATEGY.UseCredentials(); - domStrategy.insertElement = jest.fn((el: HTMLScriptElement) => { + domStrategy.insertElement = vi.fn((el: HTMLScriptElement) => { setTimeout(() => { el.onload( new CustomEvent('success', { @@ -64,7 +64,7 @@ describe('StyleLoadingStrategy', () => { const domStrategy = DOM_STRATEGY.PrependToHead(); const crossOriginStrategy = CROSS_ORIGIN_STRATEGY.UseCredentials(); - domStrategy.insertElement = jest.fn((el: HTMLLinkElement) => { + domStrategy.insertElement = vi.fn((el: HTMLLinkElement) => { setTimeout(() => { el.onload( new CustomEvent('success', { diff --git a/npm/ng-packs/packages/core/src/lib/tests/local-storage.service.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/local-storage.service.spec.ts index ad51bbda2b..8cfd8853a8 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/local-storage.service.spec.ts +++ b/npm/ng-packs/packages/core/src/lib/tests/local-storage.service.spec.ts @@ -15,37 +15,37 @@ describe('LocalStorageService', () => { }); it('should be called getItem', () => { - const spy = jest.spyOn(service, 'getItem'); + const spy = vi.spyOn(service, 'getItem'); service.getItem('test'); expect(spy).toHaveBeenCalled(); }); it('should be called setItem', () => { - const spy = jest.spyOn(service, 'setItem'); + const spy = vi.spyOn(service, 'setItem'); service.setItem('test', 'value'); expect(spy).toHaveBeenCalled(); }); it('should be called removeItem', () => { - const spy = jest.spyOn(service, 'removeItem'); + const spy = vi.spyOn(service, 'removeItem'); service.removeItem('test'); expect(spy).toHaveBeenCalled(); }); it('should be called clear', () => { - const spy = jest.spyOn(service, 'clear'); + const spy = vi.spyOn(service, 'clear'); service.clear(); expect(spy).toHaveBeenCalled(); }); it('should be called key', () => { - const spy = jest.spyOn(service, 'key'); + const spy = vi.spyOn(service, 'key'); service.key(0); expect(spy).toHaveBeenCalled(); }); it('should be called length', () => { - const spy = jest.spyOn(service, 'length', 'get'); + const spy = vi.spyOn(service, 'length', 'get'); service.length; expect(spy).toHaveBeenCalled(); }); diff --git a/npm/ng-packs/packages/core/src/lib/tests/localization.pipe.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/localization.pipe.spec.ts index 4eed4b65b9..82446b473a 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/localization.pipe.spec.ts +++ b/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 { LocalizationService } from '../services/localization.service'; @@ -19,7 +19,7 @@ describe('LocalizationPipe', () => { }); it('should call getLocalization selector', () => { - const translateSpy = jest.spyOn(localizationService, 'instant'); + const translateSpy = vi.spyOn(localizationService, 'instant'); pipe.transform('test', '1', '2'); pipe.transform('test2', ['3', '4'] as any); diff --git a/npm/ng-packs/packages/core/src/lib/tests/localization.service.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/localization.service.spec.ts index 364bbb65ff..dee26425ea 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/localization.service.spec.ts +++ b/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 { LocalizationService } from '../services/localization.service'; import { SessionStateService } from '../services/session-state.service'; @@ -18,26 +18,26 @@ describe('LocalizationService', () => { { provide: SessionStateService, useValue: { - getLanguage: jest.fn(() => 'en'), - setLanguage: jest.fn(), - getLanguage$: jest.fn(() => new Subject()), - onLanguageChange$: jest.fn(() => new Subject()), + getLanguage: vi.fn(() => 'en'), + setLanguage: vi.fn(), + getLanguage$: vi.fn(() => new Subject()), + onLanguageChange$: vi.fn(() => new Subject()), }, }, { provide: ConfigStateService, useValue: { - getOne: jest.fn(), - refreshAppState: jest.fn(), - getDeep: jest.fn(), - getDeep$: jest.fn(() => new Subject()), - getOne$: jest.fn(() => new Subject()), + getOne: vi.fn(), + refreshAppState: vi.fn(), + getDeep: vi.fn(), + getDeep$: vi.fn(() => new Subject()), + getOne$: vi.fn(() => new Subject()), }, }, { provide: Injector, useValue: { - get: jest.fn(), + get: vi.fn(), }, }, ], diff --git a/npm/ng-packs/packages/core/src/lib/tests/multi-tenancy-utils.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/multi-tenancy-utils.spec.ts index 5e49b64d22..753ac12e52 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/multi-tenancy-utils.spec.ts +++ b/npm/ng-packs/packages/core/src/lib/tests/multi-tenancy-utils.spec.ts @@ -1,5 +1,5 @@ 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 { 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 () => { const environmentService = spectator.inject(EnvironmentService); const multiTenancyService = spectator.inject(MultiTenancyService); - const setTenantByName = jest.spyOn(multiTenancyService, 'setTenantByName'); - const getEnvironmentSpy = jest.spyOn(environmentService, 'getEnvironment'); - const setStateSpy = jest.spyOn(environmentService, 'setState'); + const setTenantByName = vi.spyOn(multiTenancyService, 'setTenantByName'); + const getEnvironmentSpy = vi.spyOn(environmentService, 'getEnvironment'); + const setStateSpy = vi.spyOn(environmentService, 'setState'); getEnvironmentSpy.mockReturnValue(clone(environment)); diff --git a/npm/ng-packs/packages/core/src/lib/tests/permission.directive.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/permission.directive.spec.ts index a2f07e7be9..afb3ba2eb1 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/permission.directive.spec.ts +++ b/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 { PermissionDirective } from '../directives/permission.directive'; import { PermissionService } from '../services/permission.service'; @@ -13,8 +13,8 @@ describe('PermissionDirective', () => { directive: PermissionDirective, providers: [ { provide: PermissionService, useValue: { getGrantedPolicy$: () => grantedPolicy$ } }, - { provide: QUEUE_MANAGER, useValue: { add: jest.fn() } }, - { provide: ChangeDetectorRef, useValue: { detectChanges: jest.fn() } }, + { provide: QUEUE_MANAGER, useValue: { add: vi.fn() } }, + { provide: ChangeDetectorRef, useValue: { detectChanges: vi.fn() } }, ], }); diff --git a/npm/ng-packs/packages/core/src/lib/tests/replaceable-template.directive.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/replaceable-template.directive.spec.ts index 3bf3a6d8bb..08075ee7f4 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/replaceable-template.directive.spec.ts +++ b/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 { Router } from '@angular/router'; -import { createDirectiveFactory, SpectatorDirective } from '@ngneat/spectator/jest'; +import { createDirectiveFactory, SpectatorDirective } from '@ngneat/spectator/vitest'; import { BehaviorSubject } from 'rxjs'; import { ReplaceableTemplateDirective } from '../directives/replaceable-template.directive'; import { ReplaceableComponents } from '../models/replaceable-components'; @@ -50,8 +50,8 @@ describe('ReplaceableTemplateDirective', () => { }); describe('without external component', () => { - const twoWayChange = jest.fn(a => a); - const someOutput = jest.fn(a => a); + const twoWayChange = vi.fn(a => a); + const someOutput = vi.fn(a => a); beforeEach(() => { spectator = createDirective( @@ -88,8 +88,8 @@ describe('ReplaceableTemplateDirective', () => { hostProps: { oneWay: { label: 'Test' }, twoWay: false, - twoWayChange: jest.fn(), - someOutput: jest.fn(), + twoWayChange: vi.fn(), + someOutput: vi.fn(), }, }, ); diff --git a/npm/ng-packs/packages/core/src/lib/tests/rest.service.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/rest.service.spec.ts index 5cbd56328a..06cf9bec18 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/rest.service.spec.ts +++ b/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 { of, throwError } from 'rxjs'; import { catchError } from 'rxjs/operators'; +import { firstValueFrom } from 'rxjs'; import { Rest } from '../models/rest'; import { EnvironmentService } from '../services/environment.service'; import { HttpErrorReporterService } from '../services/http-error-reporter.service'; @@ -75,7 +76,7 @@ describe('HttpClient testing', () => { }); 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 }); @@ -84,7 +85,7 @@ describe('HttpClient testing', () => { }); test('should handle the error', () => { - const spy = jest.spyOn(httpErrorReporter, 'reportError'); + const spy = vi.spyOn(httpErrorReporter, 'reportError'); spectator.service .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', () => { - const spy = jest.spyOn(httpErrorReporter, 'reportError'); + const spy = vi.spyOn(httpErrorReporter, 'reportError'); spectator.service .request( diff --git a/npm/ng-packs/packages/core/src/lib/tests/route-utils.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/route-utils.spec.ts index 3ee908251a..f8443a1804 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/route-utils.spec.ts +++ b/npm/ng-packs/packages/core/src/lib/tests/route-utils.spec.ts @@ -1,6 +1,6 @@ import { Component } from '@angular/core'; 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 { RoutesService } from '../services/routes.service'; import { findRoute, getRoutePath } from '../utils/route-utils'; @@ -23,7 +23,7 @@ describe('Route Utils', () => { `( 'should find $expected in $count turns when path is $path', 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 route = findRoute(routes, path); expect(route).toBe(expected); diff --git a/npm/ng-packs/packages/core/src/lib/tests/router-events.service.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/router-events.service.spec.ts index bc22065aa7..95f199f381 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/router-events.service.spec.ts +++ b/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 { Subject } from 'rxjs'; -import { createServiceFactory, SpectatorService } from '@ngneat/spectator/jest'; +import { createServiceFactory, SpectatorService } from '@ngneat/spectator/vitest'; import { take } from 'rxjs/operators'; import { NavigationEventKey, RouterEvents } from '../services/router-events.service'; diff --git a/npm/ng-packs/packages/core/src/lib/tests/router-outlet.component.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/router-outlet.component.spec.ts index c76876f77a..00ec796e55 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/router-outlet.component.spec.ts +++ b/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 { RouterOutletComponent } from '../components/router-outlet.component'; diff --git a/npm/ng-packs/packages/core/src/lib/tests/routes.handler.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/routes.handler.spec.ts index 853331539d..32ea1e4324 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/routes.handler.spec.ts +++ b/npm/ng-packs/packages/core/src/lib/tests/routes.handler.spec.ts @@ -1,7 +1,7 @@ import { Router } from '@angular/router'; import { RoutesHandler } from '../handlers/routes.handler'; import { RoutesService } from '../services/routes.service'; -import { createServiceFactory, SpectatorService } from '@ngneat/spectator/jest'; +import { createServiceFactory, SpectatorService } from '@ngneat/spectator/vitest'; describe('Routes Handler', () => { let spectator: SpectatorService; @@ -15,7 +15,7 @@ describe('Routes Handler', () => { { provide: RoutesService, useValue: { - add: jest.fn(), + add: vi.fn(), }, }, { diff --git a/npm/ng-packs/packages/core/src/lib/tests/routes.service.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/routes.service.spec.ts index 71e71945d0..158c9ca644 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/routes.service.spec.ts +++ b/npm/ng-packs/packages/core/src/lib/tests/routes.service.spec.ts @@ -1,5 +1,5 @@ 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 { HttpClient } from '@angular/common/http'; import { ConfigStateService } from '../services/config-state.service'; @@ -33,51 +33,51 @@ describe('Routes Service', () => { { provide: HttpClient, useValue: { - get: jest.fn(), - post: jest.fn(), - put: jest.fn(), - delete: jest.fn(), + get: vi.fn(), + post: vi.fn(), + put: vi.fn(), + delete: vi.fn(), }, }, { provide: ConfigStateService, useValue: { - getOne: jest.fn(), - getDeep: jest.fn(), - getDeep$: jest.fn(() => ({ subscribe: jest.fn() })), - createOnUpdateStream: jest.fn(() => ({ - subscribe: jest.fn(() => ({ unsubscribe: jest.fn() })) + getOne: vi.fn(), + getDeep: vi.fn(), + getDeep$: vi.fn(() => ({ subscribe: vi.fn() })), + createOnUpdateStream: vi.fn(() => ({ + subscribe: vi.fn(() => ({ unsubscribe: vi.fn() })) })), }, }, { provide: AbpApplicationConfigurationService, useValue: { - get: jest.fn(), + get: vi.fn(), }, }, { provide: RestService, useValue: { - request: jest.fn(), + request: vi.fn(), }, }, { provide: EnvironmentService, useValue: { - getEnvironment: jest.fn(), + getEnvironment: vi.fn(), }, }, { provide: HttpErrorReporterService, useValue: { - reportError: jest.fn(), + reportError: vi.fn(), }, }, { provide: ExternalHttpClient, useValue: { - request: jest.fn(), + request: vi.fn(), }, }, { diff --git a/npm/ng-packs/packages/core/src/lib/tests/safe-html.pipe.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/safe-html.pipe.spec.ts index 69ecfeb3a2..a36b2062bc 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/safe-html.pipe.spec.ts +++ b/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'; describe('SafeHtmlPipe', () => { @@ -27,7 +27,7 @@ describe('SafeHtmlPipe', () => { }); it('should sanitize unsafe HTML content', () => { - const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => undefined); + const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => undefined); const input = `

Click here!

`; const result = pipe.transform(input); expect(result).toBe(`

Click here!

`); diff --git a/npm/ng-packs/packages/core/src/lib/tests/show-password-directive.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/show-password-directive.spec.ts index a1e766dc51..14994fc699 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/show-password-directive.spec.ts +++ b/npm/ng-packs/packages/core/src/lib/tests/show-password-directive.spec.ts @@ -1,55 +1,55 @@ -import { Component, DebugElement } from '@angular/core' -import { ComponentFixture, TestBed } from '@angular/core/testing' -import { ShowPasswordDirective } from '../directives'; -import { By } from '@angular/platform-browser'; - -@Component({ - standalone:true, - template: ` - - - - `, - imports:[ShowPasswordDirective] -}) -class TestComponent { - showPassword = false -} - -describe('ShowPasswordDirective',()=>{ - let fixture: ComponentFixture;; - let des : DebugElement[]; - let desAll : DebugElement[]; - let bareInput; - - beforeEach(()=>{ - fixture = TestBed.configureTestingModule({ - imports: [ TestComponent ] - }).createComponent(TestComponent) - - fixture.detectChanges(); - - des = fixture.debugElement.queryAll(By.directive(ShowPasswordDirective)); - - desAll = fixture.debugElement.queryAll(By.all()); - - bareInput = fixture.debugElement.query(By.css('input:not([abpShowPassword])')); - }) - - it('should have three input has ShowPasswordDirective elements', () => { - expect(des.length).toBe(3); - }); - - test.each([[0,'text'],[1,'password'],[2,'text'],[3,'password']])('%p. input type must be %p)', (index,inpType) => { - const inputType = desAll[index].nativeElement.type; - expect(inputType).toBe(inpType); - }); - - it('should have three input has ShowPasswordDirective elements', () => { - const input = des[2].nativeElement - expect(input.type).toBe('password') - fixture.componentInstance.showPassword = true - fixture.detectChanges() - expect(input.type).toBe('text') - }); +import { Component, DebugElement } from '@angular/core' +import { ComponentFixture, TestBed } from '@angular/core/testing' +import { ShowPasswordDirective } from '../directives'; +import { By } from '@angular/platform-browser'; + +@Component({ + standalone:true, + template: ` + + + + `, + imports:[ShowPasswordDirective] +}) +class TestComponent { + showPassword = false +} + +describe('ShowPasswordDirective',()=>{ + let fixture: ComponentFixture;; + let des : DebugElement[]; + let desAll : DebugElement[]; + let bareInput; + + beforeEach(()=>{ + fixture = TestBed.configureTestingModule({ + imports: [ TestComponent ] + }).createComponent(TestComponent) + + fixture.detectChanges(); + + des = fixture.debugElement.queryAll(By.directive(ShowPasswordDirective)); + + desAll = fixture.debugElement.queryAll(By.all()); + + bareInput = fixture.debugElement.query(By.css('input:not([abpShowPassword])')); + }) + + it('should have three input has ShowPasswordDirective elements', () => { + expect(des.length).toBe(3); + }); + + test.each([[0,'text'],[1,'password'],[2,'text'],[3,'password']])('%p. input type must be %p)', (index,inpType) => { + const inputType = desAll[index].nativeElement.type; + expect(inputType).toBe(inpType); + }); + + it('should have three input has ShowPasswordDirective elements', () => { + const input = des[2].nativeElement + expect(input.type).toBe('password') + fixture.componentInstance.showPassword = true + fixture.detectChanges() + expect(input.type).toBe('text') + }); }); \ No newline at end of file diff --git a/npm/ng-packs/packages/core/src/lib/tests/sort.pipe.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/sort.pipe.spec.ts index 0d60ab0b21..7cc830990c 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/sort.pipe.spec.ts +++ b/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'; describe('SortPipe', () => { diff --git a/npm/ng-packs/packages/core/src/lib/tests/stop-propagation.directive.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/stop-propagation.directive.spec.ts index f054601efa..691b293d56 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/stop-propagation.directive.spec.ts +++ b/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'; describe('StopPropagationDirective', () => { let spectator: SpectatorDirective; let directive: StopPropagationDirective; let link: HTMLAnchorElement; - const childClickEventFn = jest.fn(() => null); - const parentClickEventFn = jest.fn(() => null); + const childClickEventFn = vi.fn(() => null); + const parentClickEventFn = vi.fn(() => null); const createDirective = createDirectiveFactory({ directive: StopPropagationDirective, }); diff --git a/npm/ng-packs/packages/core/src/lib/tests/subscription.service.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/subscription.service.spec.ts index d0c8c4754f..191c5868c3 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/subscription.service.spec.ts +++ b/npm/ng-packs/packages/core/src/lib/tests/subscription.service.spec.ts @@ -14,8 +14,8 @@ describe('SubscriptionService', () => { describe('#addOne', () => { it('should subscribe to given observable with next and error functions and return the Subscription instance', () => { - const next = jest.fn(); - const error = jest.fn(); + const next = vi.fn(); + const error = vi.fn(); const subscription = service.addOne(of(null), next, error); expect(subscription).toBeInstanceOf(Subscription); expect(next).toHaveBeenCalledWith(null); @@ -24,7 +24,7 @@ describe('SubscriptionService', () => { }); 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); expect(subscription).toBeInstanceOf(Subscription); expect(observer.next).toHaveBeenCalledWith(null);