Closed TMaszko closed 2 months ago
Hello @TMaszko, thanks for reporting this issue. I don't understand the problem here though, if I follow the steps to reproduce then the test will fail because the element gets removed after the waitFor has timed out, which is the expected behavior. In the waitFor if we use a getBy query and get an error it means the element was removed so it will be successful but that is the expected behavior. Could you provide the full code for a test example that would not work as expected?
Hi @pierrezimmermannbam ! My fault, Sorry I think I've missed really important detail at that point. Everything is clear now! Thanks a lot :)
Describe the bug
Docs says here: https://callstack.github.io/react-native-testing-library/docs/api#waitforelementtoberemoved that we could useany of getBy, getAllBy, queryBy and queryAllBy queries for expectation parameter
but during writing some tests I discovered thatget
type queries are not fully compatible withwaitForElementToBeRemoved
because when the error is thrown it will be caught by thecatch
block andinitialElements
will be returned. Due to the fact thatwaitFor
will stop onceexpectation
doesn't throw an error it will callonDone
callback with the result which will "work" only because the element was removed in the first cycle (firstcheckExpectation
call).Expected behaviour
Docs shouldn't mention
get
type queries or it should throw an error instead of returninginitialElements
in the catch block.Steps to Reproduce
setTimeout
with 1000ms timeout.waitForElementToBeRemoved
with aget
type query(getByText
) for example :)Screenshots
Versions
npmPackages: @testing-library/react-native: 12.4.5 => 12.4.5 react: 18.2.0 => 18.2.0 react-native: 0.73.6 => 0.73.6 react-test-renderer: 18.2.0 => 18.2.0