From 11988dfb2a7362a193dd1a0e8e986c4d6d96170e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Hlad=C3=ADk?= Date: Sat, 25 May 2024 00:03:32 +0200 Subject: [PATCH] chore(tests): tests fixed --- angular.json | 1 - projects/demo/src/app/app.component.spec.ts | 13 ++--- projects/demo/src/polyfills.ts | 52 ------------------- projects/demo/src/test.ts | 1 - projects/demo/tsconfig.app.json | 2 +- projects/demo/tsconfig.spec.json | 2 +- .../src/lib/ngx-app-version.directive.spec.ts | 4 +- projects/ngx-app-version/src/test.ts | 2 - 8 files changed, 12 insertions(+), 65 deletions(-) delete mode 100644 projects/demo/src/polyfills.ts diff --git a/angular.json b/angular.json index 890b95f..613f272 100644 --- a/angular.json +++ b/angular.json @@ -129,7 +129,6 @@ "builder": "@angular-devkit/build-angular:karma", "options": { "main": "projects/demo/src/test.ts", - "polyfills": "projects/demo/src/polyfills.ts", "tsConfig": "projects/demo/tsconfig.spec.json", "karmaConfig": "projects/demo/karma.conf.js", "assets": [ diff --git a/projects/demo/src/app/app.component.spec.ts b/projects/demo/src/app/app.component.spec.ts index 080d069..59d9ae3 100644 --- a/projects/demo/src/app/app.component.spec.ts +++ b/projects/demo/src/app/app.component.spec.ts @@ -1,4 +1,5 @@ -import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; +import { provideExperimentalZonelessChangeDetection } from '@angular/core'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import { NgxAppVersionOptions, provideAppVersion } from 'projects/ngx-app-version/src/public-api'; import { AppComponent } from './app.component'; @@ -10,23 +11,23 @@ describe('AppComponent', () => { version: '1.0.0' }; - beforeEach(waitForAsync(() => { + beforeEach(() => { TestBed.configureTestingModule({ imports: [AppComponent], - providers: [provideAppVersion(mockOptions)] + providers: [provideExperimentalZonelessChangeDetection(), provideAppVersion(mockOptions)] }).compileComponents(); fixture = TestBed.createComponent(AppComponent); component = fixture.componentInstance; - })); + }); it('should create the app', () => { expect(component).toBeTruthy(); }); - it(`should get github link`, waitForAsync(() => { + it(`should get github link`, () => { fixture.detectChanges(); const compiled = fixture.debugElement.nativeElement; expect(compiled.querySelector('.github-logo').href).toContain('https://github.com/celtian/ngx-app-version'); - })); + }); }); diff --git a/projects/demo/src/polyfills.ts b/projects/demo/src/polyfills.ts deleted file mode 100644 index 4efb94c..0000000 --- a/projects/demo/src/polyfills.ts +++ /dev/null @@ -1,52 +0,0 @@ -/** - * This file includes polyfills needed by Angular and is loaded before the app. - * You can add your own extra polyfills to this file. - * - * This file is divided into 2 sections: - * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. - * 2. Application imports. Files imported after ZoneJS that should be loaded before your main - * file. - * - * The current setup is for so-called "evergreen" browsers; the last versions of browsers that - * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera), - * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile. - * - * Learn more in https://angular.io/guide/browser-support - */ - -/*************************************************************************************************** - * BROWSER POLYFILLS - */ - -/** - * By default, zone.js will patch all possible macroTask and DomEvents - * user can disable parts of macroTask/DomEvents patch by setting following flags - * because those flags need to be set before `zone.js` being loaded, and webpack - * will put import in the top of bundle, so user need to create a separate file - * in this directory (for example: zone-flags.ts), and put the following flags - * into that file, and then add the following code before importing zone.js. - * import './zone-flags'; - * - * The flags allowed in zone-flags.ts are listed here. - * - * The following flags will work for all browsers. - * - * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame - * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick - * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames - * - * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js - * with the following flag, it will bypass `zone.js` patch for IE/Edge - * - * (window as any).__Zone_enable_cross_context_check = true; - * - */ - -/*************************************************************************************************** - * Zone JS is required by default for Angular itself. - */ -import 'zone.js'; // Included with Angular CLI. - -/*************************************************************************************************** - * APPLICATION IMPORTS - */ diff --git a/projects/demo/src/test.ts b/projects/demo/src/test.ts index e275835..b75822a 100644 --- a/projects/demo/src/test.ts +++ b/projects/demo/src/test.ts @@ -1,6 +1,5 @@ // This file is required by karma.conf.js and loads recursively all the .spec and framework files -import 'zone.js/testing'; import { getTestBed } from '@angular/core/testing'; import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing'; diff --git a/projects/demo/tsconfig.app.json b/projects/demo/tsconfig.app.json index 784dba9..288bb1b 100644 --- a/projects/demo/tsconfig.app.json +++ b/projects/demo/tsconfig.app.json @@ -4,6 +4,6 @@ "outDir": "../../out-tsc/app", "types": [] }, - "files": ["src/main.ts", "src/polyfills.ts"], + "files": ["src/main.ts"], "include": ["src/**/*.d.ts"], } diff --git a/projects/demo/tsconfig.spec.json b/projects/demo/tsconfig.spec.json index d213ba2..1e76c99 100644 --- a/projects/demo/tsconfig.spec.json +++ b/projects/demo/tsconfig.spec.json @@ -4,6 +4,6 @@ "outDir": "../../out-tsc/spec", "types": ["jasmine", "node"] }, - "files": ["src/test.ts", "src/polyfills.ts"], + "files": ["src/test.ts"], "include": ["src/**/*.spec.ts", "src/**/*.d.ts"], } diff --git a/projects/ngx-app-version/src/lib/ngx-app-version.directive.spec.ts b/projects/ngx-app-version/src/lib/ngx-app-version.directive.spec.ts index 8403b39..0cdfbba 100644 --- a/projects/ngx-app-version/src/lib/ngx-app-version.directive.spec.ts +++ b/projects/ngx-app-version/src/lib/ngx-app-version.directive.spec.ts @@ -1,4 +1,4 @@ -import { Component, ElementRef, Renderer2 } from '@angular/core'; +import { Component, ElementRef, Renderer2, provideExperimentalZonelessChangeDetection } from '@angular/core'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; import { NgxAppVersionDirective } from './ngx-app-version.directive'; @@ -24,6 +24,7 @@ describe('NgxAppVersionDirective', () => { declarations: [TestComponent], imports: [NgxAppVersionDirective], providers: [ + provideExperimentalZonelessChangeDetection(), provideAppVersion(mockOptions), { provide: ElementRef, useValue: {} }, { provide: Renderer2, useValue: {} } @@ -64,6 +65,7 @@ describe('NgxAppVersionDirective', () => { declarations: [TestHostComponent], imports: [], providers: [ + provideExperimentalZonelessChangeDetection(), provideAppVersion(mockOptions), { provide: ElementRef, useValue: {} }, { provide: Renderer2, useValue: {} } diff --git a/projects/ngx-app-version/src/test.ts b/projects/ngx-app-version/src/test.ts index 3c10acf..b75822a 100644 --- a/projects/ngx-app-version/src/test.ts +++ b/projects/ngx-app-version/src/test.ts @@ -1,7 +1,5 @@ // This file is required by karma.conf.js and loads recursively all the .spec and framework files -import 'zone.js'; -import 'zone.js/testing'; import { getTestBed } from '@angular/core/testing'; import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';