TypeError: Right-hand side of 'instanceof' HTMLElement is not callable karma jasmin angular

Discussão em 'Angular' iniciado por Gregory Boutte, Março 13, 2025.

  1. I have an angular project that was updated recently. With it I also updated the libraries.

    The project is at angular 18 There is the library primeng v18.

    On this project there is Karma / Jasmine for the tests.

    • jasmine-core v5
    • karma v6.4

    Since the updates I get some error when I run the tests. It's always the same error:

    TypeError: Right-hand side of 'instanceof' is not callable
    at isElement (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@primeuix/utils/dom/index.mjs:238:51)
    at findSingle (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@primeuix/utils/dom/index.mjs:428:10)
    at ButtonDirective.createIcon (http://localhost:9876/_karma_webpack_/webpack:/node_modules/primeng/fesm2022/primeng-button.mjs:1087:35)
    at ButtonDirective.call [as ngAfterViewInit] (http://localhost:9876/_karma_webpack_/webpack:/node_modules/primeng/fesm2022/primeng-button.mjs:1004:14)
    at callHookInternal (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2022/core.mjs:5154:14)
    at callHook (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2022/core.mjs:5181:13)
    at callHooks (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2022/core.mjs:5135:17)
    at executeInitAndCheckHooks (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2022/core.mjs:5085:9)
    at refreshView (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2022/core.mjs:13852:21)
    at detectChangesInView (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2022/core.mjs:13993:9)


    It's something that is coming from the library primeuix that is used by primeng.

    Here is the code of the library:

    export default function isElement(element: unknown): element is Element {
    return typeof HTMLElement !== 'undefined' ? element instanceof HTMLElement : element !== null && typeof element === 'object' && (element as Element).nodeType === 1 && typeof (element as Element).nodeName === 'string';
    }


    From my understanding it's precisely this: element instanceof HTMLElement, and HTMLElement is not callable.

    Do you know why there is this error ? And how I could fix it ?

    I tried:

    • To migrate to jest: But there is a lot of test to fix to use jest inside all files, so for now I prefer not to use this.
    • To use jsdom browser: It did not find a way to make it run.
    • To define a variable (HTMLElement) globally for the test, but it did not work. And HTMLElement was already defined when I did a console log.

    Continue reading...

Compartilhe esta Página