Skip to content

Instantly share code, notes, and snippets.

@edezekiel
Created March 11, 2023 15:57
Mock service provided to component using constructor-based DI
import { DemoService } from '../demo.service';
import { DemoComponent } from './demo.component';
describe('DemoComponent', () => {
it('should create', () => {
const serviceMock = { getWidgets: jest.fn() };
const component = new DemoComponent(serviceMock as DemoService);
expect(component).toBeTruthy();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment