React-native-testing-library: check if a matching node doesn't exist

Created on 27 May 2020  路  1Comment  路  Source: callstack/react-native-testing-library

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?

question

Most helpful comment

You can use toThrow Jest matcher:

expect(() => UNSAFE_getByType(ComponentName)).toThrow("no instances found")

or use queryByType and assert .toEqual(null)

>All comments

You can use toThrow Jest matcher:

expect(() => UNSAFE_getByType(ComponentName)).toThrow("no instances found")

or use queryByType and assert .toEqual(null)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

CodingItWrong picture CodingItWrong  路  4Comments

acollazomayer picture acollazomayer  路  3Comments

MuhmdRaouf picture MuhmdRaouf  路  5Comments

jonmchan picture jonmchan  路  11Comments

bitttttten picture bitttttten  路  9Comments