Skip to content

Commit

Permalink
Migrate unit tests to Angular 18 syntax (#1153)
Browse files Browse the repository at this point in the history
  • Loading branch information
mraible authored Jun 6, 2024
1 parent 4b9ea7a commit e0d9753
Show file tree
Hide file tree
Showing 16 changed files with 71 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';

import { AccountPage } from './account.page';
import { TranslateModule } from '@ngx-translate/core';
import { RouterTestingModule } from '@angular/router/testing';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
import { provideHttpClientTesting } from '@angular/common/http/testing';

describe('AccountPage', () => {
let component: AccountPage;
Expand All @@ -14,7 +14,8 @@ describe('AccountPage', () => {
TestBed.configureTestingModule({
declarations: [AccountPage],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
imports: [TranslateModule.forRoot(), RouterTestingModule, HttpClientTestingModule],
imports: [TranslateModule.forRoot()],
providers: [provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting()],
}).compileComponents();
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';

import { EntitiesPage } from './entities.page';
import { TranslateModule } from '@ngx-translate/core';
import { RouterTestingModule } from '@angular/router/testing';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
import { provideHttpClientTesting } from '@angular/common/http/testing';

describe('EntitiesPage', () => {
let component: EntitiesPage;
Expand All @@ -14,7 +14,8 @@ describe('EntitiesPage', () => {
TestBed.configureTestingModule({
declarations: [EntitiesPage],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
imports: [TranslateModule.forRoot(), RouterTestingModule, HttpClientTestingModule],
imports: [TranslateModule.forRoot()],
providers: [provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting()],
}).compileComponents();
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';

import { HomePage } from './home.page';
import { TranslateModule } from '@ngx-translate/core';
import { RouterTestingModule } from '@angular/router/testing';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
import { provideHttpClientTesting } from '@angular/common/http/testing';

describe('HomePage', () => {
let component: HomePage;
Expand All @@ -14,7 +14,8 @@ describe('HomePage', () => {
TestBed.configureTestingModule({
declarations: [HomePage],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
imports: [TranslateModule.forRoot(), RouterTestingModule, HttpClientTestingModule],
imports: [TranslateModule.forRoot()],
providers: [provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting()],
}).compileComponents();
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';

import { LoginPage } from './login.page';
import { TranslateModule } from '@ngx-translate/core';
import { RouterTestingModule } from '@angular/router/testing';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
import { provideHttpClientTesting } from '@angular/common/http/testing';

describe('LoginPage', () => {
let component: LoginPage;
Expand All @@ -14,7 +14,8 @@ describe('LoginPage', () => {
TestBed.configureTestingModule({
declarations: [LoginPage],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
imports: [TranslateModule.forRoot(), RouterTestingModule, HttpClientTestingModule],
imports: [TranslateModule.forRoot()],
providers: [provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting()],
}).compileComponents();
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';

import { SignupPage } from './signup.page';
import { TranslateModule } from '@ngx-translate/core';
import { RouterTestingModule } from '@angular/router/testing';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
import { provideHttpClientTesting } from '@angular/common/http/testing';

describe('SignupPage', () => {
let component: SignupPage;
Expand All @@ -14,7 +14,8 @@ describe('SignupPage', () => {
TestBed.configureTestingModule({
declarations: [SignupPage],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
imports: [TranslateModule.forRoot(), RouterTestingModule, HttpClientTestingModule],
imports: [TranslateModule.forRoot()],
providers: [provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting()],
}).compileComponents();
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';

import { WelcomePage } from './welcome.page';
import { TranslateModule } from '@ngx-translate/core';
import { RouterTestingModule } from '@angular/router/testing';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
import { provideHttpClientTesting } from '@angular/common/http/testing';

describe('WelcomePage', () => {
let component: WelcomePage;
Expand All @@ -14,7 +14,8 @@ describe('WelcomePage', () => {
TestBed.configureTestingModule({
declarations: [WelcomePage],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
imports: [TranslateModule.forRoot(), RouterTestingModule, HttpClientTestingModule],
imports: [TranslateModule.forRoot()],
providers: [provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting()],
}).compileComponents();
}));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { TestBed } from '@angular/core/testing';
import { LoginService } from './login.service';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
import { provideHttpClientTesting } from '@angular/common/http/testing';
import { TranslateModule } from '@ngx-translate/core';

describe('LoginService', () => {
beforeEach(() =>
TestBed.configureTestingModule({
imports: [HttpClientTestingModule, TranslateModule.forRoot()],
imports: [TranslateModule.forRoot()],
providers: [provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting()],
}),
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { TestBed } from '@angular/core/testing';
import { UserService } from './user.service';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
import { provideHttpClientTesting } from '@angular/common/http/testing';
import { TranslateModule } from '@ngx-translate/core';

describe('UserService', () => {
beforeEach(() =>
TestBed.configureTestingModule({
imports: [HttpClientTestingModule, TranslateModule.forRoot()],
imports: [TranslateModule.forRoot()],
providers: [provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting()],
}),
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { TestBed, fakeAsync, tick } from '@angular/core/testing';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
import { provideHttpClientTesting } from '@angular/common/http/testing';

import { Platform } from '@ionic/angular';
import { IonicStorageModule } from '@ionic/storage-angular';
Expand Down Expand Up @@ -46,11 +47,13 @@ describe('AppComponent', () => {

TestBed.configureTestingModule({
declarations: [AppComponent],
imports: [TranslateModule.forRoot(), HttpClientTestingModule, IonicStorageModule.forRoot()],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
imports: [TranslateModule.forRoot(), IonicStorageModule.forRoot()],
providers: [
{ provide: Platform, useValue: platformSpy },
{ provide: AuthService, useValue: authServiceSpy },
provideHttpClient(withInterceptorsFromDi()),
provideHttpClientTesting(),
],
}).compileComponents();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { IonicStorageModule } from '@ionic/storage-angular';
import { TranslateModule } from '@ngx-translate/core';
import { RouterTestingModule } from '@angular/router/testing';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
import { provideHttpClientTesting } from '@angular/common/http/testing';
import { HomePage } from './home.page';
import { AuthModule } from '../../auth/auth.module';

Expand All @@ -15,7 +15,8 @@ describe('HomePage', () => {
TestBed.configureTestingModule({
declarations: [HomePage],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
imports: [TranslateModule.forRoot(), RouterTestingModule, HttpClientTestingModule, IonicStorageModule.forRoot(), AuthModule],
imports: [TranslateModule.forRoot(), IonicStorageModule.forRoot(), AuthModule],
providers: [provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting()],
}).compileComponents();
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { IonicStorageModule } from '@ionic/storage-angular';
import { TranslateModule } from '@ngx-translate/core';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
import { provideHttpClientTesting } from '@angular/common/http/testing';
import { LoginPage } from './login.page';
import { AuthModule } from '../../auth/auth.module';

Expand All @@ -15,7 +15,8 @@ describe('LoginPage', () => {
TestBed.configureTestingModule({
declarations: [LoginPage],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
imports: [TranslateModule.forRoot(), RouterTestingModule, HttpClientTestingModule, IonicStorageModule.forRoot(), AuthModule],
imports: [TranslateModule.forRoot(), IonicStorageModule.forRoot(), AuthModule],
providers: [provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting()],
}).compileComponents();
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { TranslateModule } from '@ngx-translate/core';
import { IonicStorageModule } from '@ionic/storage-angular';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
import { provideHttpClientTesting } from '@angular/common/http/testing';
import { WelcomePage } from './welcome.page';
import { AuthModule } from '../../auth/auth.module';

Expand All @@ -15,7 +15,8 @@ describe('WelcomePage', () => {
TestBed.configureTestingModule({
declarations: [WelcomePage],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
imports: [TranslateModule.forRoot(), HttpClientTestingModule, IonicStorageModule.forRoot(), RouterTestingModule, AuthModule],
imports: [TranslateModule.forRoot(), IonicStorageModule.forRoot(), AuthModule],
providers: [provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting()],
}).compileComponents();
}));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { IonicStorageModule } from '@ionic/storage-angular';
import { TranslateModule } from '@ngx-translate/core';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
import { provideHttpClientTesting } from '@angular/common/http/testing';
import { TestBed } from '@angular/core/testing';
import { LoginService } from './login.service';
import { AuthModule } from '../../auth/auth.module';

describe('LoginService', () => {
beforeEach(() =>
TestBed.configureTestingModule({
imports: [HttpClientTestingModule, TranslateModule.forRoot(), IonicStorageModule.forRoot(), AuthModule],
imports: [TranslateModule.forRoot(), IonicStorageModule.forRoot(), AuthModule],
providers: [provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting()],
}),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { TranslateModule } from '@ngx-translate/core';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
import { provideHttpClientTesting } from '@angular/common/http/testing';
import { ActivatedRoute } from '@angular/router';
import { of } from 'rxjs';
import { <%= entityAngularName %>DetailPage } from './<%= entityFileName %>-detail';
Expand All @@ -39,13 +39,11 @@ describe('<%= entityAngularName %>DetailPage', () => {
TestBed.configureTestingModule({
declarations: [<%= entityAngularName %>DetailPage],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
imports: [
TranslateModule.forRoot(),
HttpClientTestingModule,
RouterTestingModule,
],
imports: [TranslateModule.forRoot()],
providers: [
{ provide: ActivatedRoute, useValue: activatedRouteMock }
{ provide: ActivatedRoute, useValue: activatedRouteMock },
provideHttpClient(withInterceptorsFromDi()),
provideHttpClientTesting(),
]
}).compileComponents();
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { TranslateModule } from '@ngx-translate/core';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
import { provideHttpClientTesting } from '@angular/common/http/testing';
import { ActivatedRoute } from '@angular/router';
import { of } from 'rxjs';
import { IonicModule } from '@ionic/angular';
Expand Down Expand Up @@ -49,13 +49,13 @@ const activatedRouteMock = ({ data: of({ data: entityMock }) } as any) as Activa
schemas: [CUSTOM_ELEMENTS_SCHEMA],
imports: [
TranslateModule.forRoot(),
HttpClientTestingModule,
RouterTestingModule,
FormsModule, ReactiveFormsModule, IonicModule ],
providers: [
{ provide: ActivatedRoute, useValue: activatedRouteMock },
{ provide: UserService, useValue: userServiceMock },
]
providers: [
{ provide: ActivatedRoute, useValue: activatedRouteMock },
{ provide: UserService, useValue: userServiceMock },
provideHttpClient(withInterceptorsFromDi()),
provideHttpClientTesting(),
]
}).compileComponents();
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { TranslateModule } from '@ngx-translate/core';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
import { provideHttpClientTesting } from '@angular/common/http/testing';
import { <%= entityAngularName %>Page } from './<%= entityFileName %>';

describe('<%= entityAngularName %>Page', () => {
Expand All @@ -31,11 +31,8 @@ describe('<%= entityAngularName %>Page', () => {
TestBed.configureTestingModule({
declarations: [<%= entityAngularName %>Page],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
imports: [
TranslateModule.forRoot(),
HttpClientTestingModule,
RouterTestingModule,
]
imports: [TranslateModule.forRoot()],
providers: [provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting()],
}).compileComponents();
}));

Expand Down

0 comments on commit e0d9753

Please sign in to comment.