angularjasminekarma-jasmineangular-decorator

Error using spyOn in a @ViewChild variable


I have a component that uses

@ViewChild(NgbDropdown) public dropdown: NgbDropdown;

this.dropdown.isOpen();

In my spec file, I need to mock the isOpen() result to true but I can't seem to spy on it.

Getting this error:

 Error: <spyOn> : could not find an object to spy upon for isOpen()
        Usage: spyOn(<object>, <methodName>)

Thanks in advance!


Solution

  • This has something to do with the linter

    This is how it should be mocked

    component.dropdown  = jasmine.createSpyObj(['isOpen']);
    
    (component.dropdown as SpyObj<NgbDropdown>).isOpen.and.returnValue(true);
    

    Thanks!