简体   繁体   中英

Argument of type '() => JQuery' is not assignable to parameter of type '() => boolean'

I am trying to write a jasmine test case for my method, but I am facing an error:

spec.ts(163,18): error TS2345: Argument of type '() => JQuery' is not assignable to parameter of type '() => boolean'.

Can you guys tell me how to fix it? Providing my code and test case below

$('.triggerKPopUpClick').click(function() {
    if ($('#financialDocumentsGrid').data("kendoGrid")) {
        $('#financialDocumentsGrid').data("kendoGrid").dataSource.data([])
    }
    that.ContractInfoPopUpWindow.data("kendoWindow").close();
    $("html, body").css("overflow", "");
});

it('triggerKPopUpClick in head', function() {
    $('.triggerKPopUpClick').trigger('click');

    waitsFor(function() {
        return $('financialDocumentsGrid').contains('financialDocumentsGrid');
    }, 'theme switcher never loaded', 10000);
});

The .contains() method checks if an element is a descendant of another one.

Syntax is $.contains(parent, child) . Returns true or false .

Check your # and . on selectors too...


EDIT

Here is an example with your code...
Notice that the elements needed for .contains() arguments must be DOM elements, not jQuery elements. That is why there is some [0] .

 it('triggerKPopUpClick in head', function() { $('.triggerKPopUpClick').trigger('click'); waitsFor(function() { return $.contains('$(#financialDocumentsGrid)[0]', ' $(#AnotherElementWhichShouldBeAChild)[0]'); }, 'theme switcher never loaded', 10000); }); 

Here's an example in CodePen .


So... That is aout .contains() "special" syntax.
You noticed that DOM element have to be sent to .contains argument as strings ?

Maybe you be interested in an alternative:

 $("#parent").find("#child").length > 0 

If there's an element having #child in the element #parent , that is also true .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM