For example, this works even if the content is added by Ajax:
Behind the scenes, Capybara will retry finding the content if it’s not yet present.
But if you write optimistic UIs that say “Added to favorites” immediately, and only then fire off the Ajax request, you may write a test more like this:
1 2 3 4
And that test will fail, because Capybara will not know to wait a while before counting favorites. It only waits on UI changes.
My workaround is to make every Ajax request update something in the UI, and wait for that:
1 2 3 4 5 6 7 8 9
1 2 3 4
1 2 3 4 5
If you have a lot of Ajax going on at once and only want to wait on one particular request, you could do the same thing but on the particular element or request, instead of capturing every request’s events like this.