From 50c5f38b122755d1a33fa0db0a59f7be201f26d3 Mon Sep 17 00:00:00 2001 From: Romanchuk Sergey Date: Mon, 3 Jun 2024 13:03:44 +0700 Subject: [PATCH] fix: tests --- .../src/app/app.component.spec.ts | 11 ++++--- .../src/app/app.component.ts | 27 ++++++++++++---- libs/angular-i18next/src/test-setup.ts | 4 +-- .../src/tests/pipes/I18NextPipe.spec.ts | 2 +- package-lock.json | 32 +++++++++---------- package.json | 2 +- 6 files changed, 46 insertions(+), 32 deletions(-) diff --git a/apps/angular-i18next-demo/src/app/app.component.spec.ts b/apps/angular-i18next-demo/src/app/app.component.spec.ts index c526b40..3d1afa1 100644 --- a/apps/angular-i18next-demo/src/app/app.component.spec.ts +++ b/apps/angular-i18next-demo/src/app/app.component.spec.ts @@ -1,14 +1,17 @@ -import { TestBed } from '@angular/core/testing'; +import { TestBed, waitForAsync } from '@angular/core/testing'; import { AppComponent } from './app.component'; import { RouterTestingModule } from '@angular/router/testing'; +import { I18NextModule } from 'angular-i18next'; +import { I18N_PROVIDERS } from './app.module'; describe('AppComponent', () => { - beforeEach(waitForAsync(() => { + beforeEach(waitForAsync(async () => { await TestBed.configureTestingModule({ - imports: [RouterTestingModule], + imports: [I18NextModule.forRoot(), RouterTestingModule], + providers: [I18N_PROVIDERS], declarations: [AppComponent], }).compileComponents(); - }); + })); it('should create the app', () => { const fixture = TestBed.createComponent(AppComponent); diff --git a/apps/angular-i18next-demo/src/app/app.component.ts b/apps/angular-i18next-demo/src/app/app.component.ts index d62173d..e015fcd 100644 --- a/apps/angular-i18next-demo/src/app/app.component.ts +++ b/apps/angular-i18next-demo/src/app/app.component.ts @@ -4,9 +4,8 @@ import { Event as RouterEvent, NavigationCancel, NavigationEnd, NavigationError, NavigationStart, Router } from '@angular/router'; import { I18NEXT_SERVICE, ITranslationService } from 'angular-i18next'; -import { filter, map, mergeMap } from 'rxjs/operators'; +import { filter, map, mergeMap, tap } from 'rxjs/operators'; -// import 'assets/ng-validation.css'; @Component({ selector: 'app', @@ -17,9 +16,16 @@ export class AppComponent implements OnInit { loading = true; start = 0; + + get title() { + return this._title.getTitle(); + } + constructor(private router: Router, - private title: Title, + private _title: Title, @Inject(I18NEXT_SERVICE) private i18NextService: ITranslationService) { + + // spinner/loader subscription router.events .subscribe((event: RouterEvent) => { @@ -42,11 +48,18 @@ export class AppComponent implements OnInit { } ngOnInit() { - this.i18NextService.events.languageChanged.subscribe(lang => { + this.i18NextService.events.languageChanged.subscribe(() => { const root = this.router.routerState.root; if (root != null && root.firstChild != null) { - const data: any = root.firstChild.data; - this.updatePageTitle(data && data.value && data.value.title); + const data = root.firstChild.data; + data + .pipe( + tap((data) => { + this.updatePageTitle(data && data['value'] && data['value'].title); + }) + ) + .subscribe(); + } }); } @@ -66,7 +79,7 @@ export class AppComponent implements OnInit { updatePageTitle(title: string): void { const newTitle = title || 'application_title'; console.log('Setting page title:', newTitle); - this.title.setTitle(newTitle); + this._title.setTitle(newTitle); console.log('Setting page title end:', newTitle); } } diff --git a/libs/angular-i18next/src/test-setup.ts b/libs/angular-i18next/src/test-setup.ts index ab3e021..b7b8d4c 100644 --- a/libs/angular-i18next/src/test-setup.ts +++ b/libs/angular-i18next/src/test-setup.ts @@ -6,6 +6,4 @@ import { } from '@angular/platform-browser-dynamic/testing'; getTestBed().resetTestEnvironment(); -getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting(), { - teardown: { destroyAfterEach: false }, -}); +getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting()); diff --git a/libs/angular-i18next/src/tests/pipes/I18NextPipe.spec.ts b/libs/angular-i18next/src/tests/pipes/I18NextPipe.spec.ts index b3f4cb9..20fc8ba 100644 --- a/libs/angular-i18next/src/tests/pipes/I18NextPipe.spec.ts +++ b/libs/angular-i18next/src/tests/pipes/I18NextPipe.spec.ts @@ -6,7 +6,7 @@ import { I18N_PROVIDERS } from '../setup'; describe('I18NextPipe tests', function () { - beforeEach(async () => { + beforeEach(() => { TestBed.configureTestingModule({ imports: [I18NextModule.forRoot()], providers: [...I18N_PROVIDERS], diff --git a/package-lock.json b/package-lock.json index 82ffd7a..9983be8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -71,7 +71,7 @@ "eslint-plugin-cypress": "2.15.1", "i18next": "23.7.6", "jest": "^29.7.0", - "jest-preset-angular": "13.1.4", + "jest-preset-angular": "~14.1.0", "keyv": "^4.5.1", "ng-packagr": "17.0.2", "np": "~8.0.4", @@ -18615,13 +18615,13 @@ } }, "node_modules/jest-preset-angular": { - "version": "13.1.4", - "resolved": "https://registry.npmjs.org/jest-preset-angular/-/jest-preset-angular-13.1.4.tgz", - "integrity": "sha512-XKeWa8Qt7p37SzlJ85qEXgig06SgkfrzV057X2GSMqfz/HLJmTUjMFkHJKe65ZaQumNQWCcXpxXREr6EfZ9bow==", + "version": "14.1.0", + "resolved": "https://registry.npmjs.org/jest-preset-angular/-/jest-preset-angular-14.1.0.tgz", + "integrity": "sha512-UJwPtpsAMl30UtBjHW0Ai0hhoKsNURC1dXH5tSYjumUsWR7iDke+oBEykz7uXv4rN+PWgeNIqkxo4KHQjOITlw==", "dev": true, "dependencies": { "bs-logger": "^0.2.6", - "esbuild-wasm": ">=0.13.8", + "esbuild-wasm": ">=0.15.13", "jest-environment-jsdom": "^29.0.0", "jest-util": "^29.0.0", "pretty-format": "^29.0.0", @@ -18631,15 +18631,15 @@ "node": "^14.15.0 || >=16.10.0" }, "optionalDependencies": { - "esbuild": ">=0.13.8" + "esbuild": ">=0.15.13" }, "peerDependencies": { - "@angular-devkit/build-angular": ">=13.0.0 <18.0.0", - "@angular/compiler-cli": ">=13.0.0 <18.0.0", - "@angular/core": ">=13.0.0 <18.0.0", - "@angular/platform-browser-dynamic": ">=13.0.0 <18.0.0", + "@angular-devkit/build-angular": ">=15.0.0 <19.0.0", + "@angular/compiler-cli": ">=15.0.0 <19.0.0", + "@angular/core": ">=15.0.0 <19.0.0", + "@angular/platform-browser-dynamic": ">=15.0.0 <19.0.0", "jest": "^29.0.0", - "typescript": ">=4.4" + "typescript": ">=4.8" } }, "node_modules/jest-regex-util": { @@ -43922,14 +43922,14 @@ "requires": {} }, "jest-preset-angular": { - "version": "13.1.4", - "resolved": "https://registry.npmjs.org/jest-preset-angular/-/jest-preset-angular-13.1.4.tgz", - "integrity": "sha512-XKeWa8Qt7p37SzlJ85qEXgig06SgkfrzV057X2GSMqfz/HLJmTUjMFkHJKe65ZaQumNQWCcXpxXREr6EfZ9bow==", + "version": "14.1.0", + "resolved": "https://registry.npmjs.org/jest-preset-angular/-/jest-preset-angular-14.1.0.tgz", + "integrity": "sha512-UJwPtpsAMl30UtBjHW0Ai0hhoKsNURC1dXH5tSYjumUsWR7iDke+oBEykz7uXv4rN+PWgeNIqkxo4KHQjOITlw==", "dev": true, "requires": { "bs-logger": "^0.2.6", - "esbuild": ">=0.13.8", - "esbuild-wasm": ">=0.13.8", + "esbuild": ">=0.15.13", + "esbuild-wasm": ">=0.15.13", "jest-environment-jsdom": "^29.0.0", "jest-util": "^29.0.0", "pretty-format": "^29.0.0", diff --git a/package.json b/package.json index 401dd5d..225b056 100644 --- a/package.json +++ b/package.json @@ -97,7 +97,7 @@ "eslint-plugin-cypress": "2.15.1", "i18next": "23.7.6", "jest": "^29.7.0", - "jest-preset-angular": "13.1.4", + "jest-preset-angular": "~14.1.0", "keyv": "^4.5.1", "ng-packagr": "17.0.2", "np": "~8.0.4",