Skip to content

Mocking

Mocking replaces real dependencies with controlled substitutes for isolated testing.

const spy = jasmine.createSpyObj('ProductService', ['getAll']);
spy.getAll.and.returnValue(of(mockProducts));
TestBed.configureTestingModule({
providers: [{ provide: ProductService, useValue: spy }]
});

Mocking is essential for isolating the unit under test from its dependencies.”