Search code examples
javascripttypescriptjasminetestcasenodelist

How to write testcase for [object NodeList] in jasmine testing?


When I try write this testcase.

 let abc = document.querySelectorAll("span");
 expect(abc).toBe(true);

I'm getting

Expected [object NodeList] to be true.


Solution

  • Well a nodelist does not take on a bool value so that test will fail. Instead check that the list is not null ( empty ).

    expect(abc).not.toBeNull()