0

I have a directive in Angular that highlights blue in style.

    import { Directive, ElementRef } from '@angular/core';

    @Directive({
      selector: '[appHighlight]'
    })
    export class HighlightDirective {
        constructor(el: ElementRef) {
          el.nativeElement.style.color = 'blue';
        }
    }

When I want to write the test is says "An argument for el was not provided" above HighlightDirective():

    import { HighlightDirective } from './highlight.directive';

    describe('HighlightDirective', () => {
      it('should create an instance', () => {
        const directive = new HighlightDirective();
        expect(directive).toBeTruthy();
      });
    });

What do I have to include in () to the HighlightDirective? Thanks!

Please help!

  • 2
    Possible duplicate of [Angular2 Inject ElementRef in unit test](https://stackoverflow.com/questions/38623065/angular2-inject-elementref-in-unit-test) – user184994 Nov 25 '18 at 20:38
  • Can you please solve. I do not understand Angular on the level as in the duplicate – ScrapyNoob Nov 25 '18 at 20:56
  • 1
    It's not Angular. It's not even TypeScript. It's general programming. You're calling a constructor that requires an argument, but you don't pass any argument. So that doesn't compile. – JB Nizet Nov 25 '18 at 22:29

0 Answers0