Skip to content

Commit

Permalink
Development: Update client tests documentation (#9913)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesWt authored Dec 2, 2024
1 parent fef2028 commit 32d001a
Showing 1 changed file with 40 additions and 40 deletions.
80 changes: 40 additions & 40 deletions docs/dev/guidelines/client-tests.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ The most basic test looks similar to this:
let someComponentFixture: ComponentFixture<SomeComponent>;
let someComponent: SomeComponent;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [],
declarations: [
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [
SomeComponent,
MockPipe(SomePipeUsedInTemplate),
MockComponent(SomeComponentUsedInTemplate),
Expand All @@ -31,11 +30,10 @@ The most basic test looks similar to this:
MockProvider(SomeServiceUsedInComponent),
],
})
.compileComponents()
.then(() => {
someComponentFixture = TestBed.createComponent(SomeComponent);
someComponent = someComponentFixture.componentInstance;
});
.compileComponents();
someComponentFixture = TestBed.createComponent(SomeComponent);
someComponent = someComponentFixture.componentInstance;
});
afterEach(() => {
Expand All @@ -60,24 +58,25 @@ Some guidelines:
describe('ParticipationSubmissionComponent', () => {
...
beforeEach(() => {
return TestBed.configureTestingModule({
imports: [ArtemisTestModule, NgxDatatableModule, ArtemisResultModule, ArtemisSharedModule, TranslateModule.forRoot(), RouterTestingModule],
declarations: [
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [
ArtemisTestModule,
NgxDatatableModule,
ArtemisResultModule,
ArtemisSharedModule,
TranslateModule.forRoot(),
ParticipationSubmissionComponent,
MockComponent(UpdatingResultComponent),
MockComponent(AssessmentDetailComponent),
MockComponent(ComplaintsForTutorComponent),
],
providers: [
...
provideRouter([]),
],
})
.overrideModule(ArtemisTestModule, { set: { declarations: [], exports: [] } })
.compileComponents()
.then(() => {
...
});
.compileComponents();
});
});
Expand All @@ -94,10 +93,12 @@ Some guidelines:
describe('ParticipationSubmissionComponent', () => {
...
beforeEach(() => {
return TestBed.configureTestingModule({
imports: [ArtemisTestModule, RouterTestingModule, NgxDatatableModule],
declarations: [
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [
ArtemisTestModule,
RouterTestingModule,
NgxDatatableModule,
ParticipationSubmissionComponent,
MockComponent(UpdatingResultComponent),
MockComponent(AssessmentDetailComponent),
Expand All @@ -110,13 +111,10 @@ Some guidelines:
MockComponent(ResultComponent),
],
providers: [
...
provideRouter([]),
],
})
.compileComponents()
.then(() => {
...
});
.compileComponents();
});
});
Expand Down Expand Up @@ -158,11 +156,16 @@ Some guidelines:

.. code:: ts
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { provideHttpClient } from '@angular/common/http';
import { provideHttpClientTesting, HttpTestingController } from '@angular/common/http/testing';
describe('SomeComponent', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
imports: [...],
providers: [
provideHttpClient(),
provideHttpClientTesting(),
],
});
...
Expand Down Expand Up @@ -221,21 +224,18 @@ Some guidelines:
let someComponentFixture: ComponentFixture<SomeComponent>;
let someComponent: SomeComponent;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [],
declarations: [
SomeComponent,
],
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [SomeComponent],
providers: [
...
],
})
.overrideTemplate(SomeComponent, '') // DO NOT DO THIS
.compileComponents()
.then(() => {
someComponentFixture = TestBed.createComponent(SomeComponent);
someComponent = someComponentFixture.componentInstance;
});
.compileComponents();
someComponentFixture = TestBed.createComponent(SomeComponent);
someComponent = someComponentFixture.componentInstance;
});
});
Expand Down

0 comments on commit 32d001a

Please sign in to comment.