I would like to write a test for a method that receives an ElementRef. I don't find a way to mock the ElementRef, can anyone help? Thanks so much!
exampleService.service.ts:
export class exampleService {
exampleMethod(elRef: ElementRef): string {
const elWidth = elRef.nativeElement.offsetWidth;
return elWidth;
}
}
testfile.service.spec.ts:
describe('ExampleService', () => {
let service: ExampleService;
beforeEach(() => {
service = TestBed.inject(ExampleService);
});
it('How to mock the ELEMENTREF?', () => {
expect(service.exampleMethod(ELEMENTREF)).toBe('100');
});
});