ื“ืœื’ ืœืชื•ื›ืŸ ื”ืจืืฉื™

Frontend Testing

Testing strategies for the Angular frontend.

Testing Stackโ€‹

ToolPurpose
JestUnit test runner
Angular TestBedComponent testing
SpectatorTest helpers (optional)
CypressE2E testing

Unit Testsโ€‹

Component Testingโ€‹

describe("DashboardComponent", () => {
let component: DashboardComponent;
let fixture: ComponentFixture<DashboardComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [DashboardComponent],
imports: [HttpClientTestingModule, TranslateModule.forRoot()],
providers: [
{ provide: EmployeesService, useValue: mockEmployeesService },
],
}).compileComponents();

fixture = TestBed.createComponent(DashboardComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it("should create", () => {
expect(component).toBeTruthy();
});
});

Service Testingโ€‹

describe("EmployeesService", () => {
let service: EmployeesService;
let httpMock: HttpTestingController;

beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
providers: [EmployeesService],
});
service = TestBed.inject(EmployeesService);
httpMock = TestBed.inject(HttpTestingController);
});

it("should fetch employees", () => {
service.getAll().subscribe((result) => {
expect(result.items.length).toBe(2);
});

const req = httpMock.expectOne("/api/employee");
expect(req.request.method).toBe("GET");
req.flush({ items: [{}, {}], total: 2 });
});
});

Running Testsโ€‹

# Run all tests
yarn test

# Run specific project tests
npx nx test gauzy

# Run with coverage
npx nx test gauzy --coverage

# Watch mode
npx nx test gauzy --watch

E2E Testsโ€‹

# Run Cypress
npx nx e2e gauzy-e2e