Mocking
Introduction
Section titled “Introduction”Mocking replaces real dependencies with controlled substitutes for isolated testing.
Jasmine Spies
Section titled “Jasmine Spies”const spy = jasmine.createSpyObj('ProductService', ['getAll']);spy.getAll.and.returnValue(of(mockProducts));
TestBed.configureTestingModule({ providers: [{ provide: ProductService, useValue: spy }]});Summary
Section titled “Summary”Mocking is essential for isolating the unit under test from its dependencies.”