Hi,
Perhaps this is found somewhere else but I couldn't find one. My scenario is straight forward:
expect(UNSAFE_getByType(ComponentName)).toEqual(undefined)
I want to make sure the ComponentName doesn't exist. The above fails because ComponentName doesn't exist indeed (no instance with node exists error) but it should pass. Currently I am doing it in a trycatch but I was wondering if there is a way to do it?
You can use toThrow Jest matcher:
expect(() => UNSAFE_getByType(ComponentName)).toThrow("no instances found")
or use queryByType and assert .toEqual(null)
Most helpful comment
You can use
toThrowJest matcher:or use
queryByTypeand assert.toEqual(null)