Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development: Update client tests documentation #9913

Merged
merged 8 commits into from
Dec 2, 2024
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
Loading