'Jest - toBeNull() and not.toBeNull() return both false

I'm using React, Jest, and React-testing-library. I want to check that some elements are not rendered on my screen.

filterElementsNotPresent.forEach(
    ({ name }) => {
      const nameLabel = queryByText(name);      
      expect(nameLabel).toBeNull();

The result is the following: enter image description here

So I tried putting the not at the start:

filterElementsNotPresent.forEach(
        ({ name }) => {
          const nameLabel = queryByText(name);      
          expect(nameLabel).not.toBeNull();

And the result is:

enter image description here

I am really lost. Can someone give me some help with this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source