nusmods icon indicating copy to clipboard operation
nusmods copied to clipboard

Fix noob React Testing Library mistakes from #3007

Open taneliang opened this issue 4 years ago • 4 comments

I added React Testing Library in https://github.com/nusmodifications/nusmods/pull/3007, but as it was the first time I used it I made some common mistakes 😅

I only found out about them when working on https://github.com/nusmodifications/nusmods/pull/3009, after which I added some commits that fix the mistakes made within the PR. However, to avoid ballooning it, I did not fix mistakes made in #3007.

It's time to fix them :)

taneliang avatar Dec 07 '20 02:12 taneliang

I think there's a flaky test in TimetableContainer.test.tsx. It may be related to this issue, but I haven't figured out how to fix it yet 😅

The error highlights the following line:

expect(await screen.findByRole('button', { name: 'Import' })).toBeInTheDocument();

Steps to reproduce

  1. Run yarn test
  2. Repeat step 1 until you see the following error message (this takes at most 4 times in my experience)

image

Additional Information

If we run with yarn test -i or run yarn test TimetableContainer, there is no error. This probably means that some other test is affecting this one.

teikjun avatar Dec 09 '20 19:12 teikjun

I can work on these issues! :)

teikjun avatar Dec 09 '20 19:12 teikjun

Interesting! I'm unable to reproduce this on my computer despite running yarn test 10 times. Not sure what you're using, but maybe it's more easily reproducible on slower computers? Or maybe this is caused by a network call we forgot to mock?

taneliang avatar Dec 18 '20 04:12 taneliang

I can work on these issues! :)

Oops, missed this. Thank you! :D Feel free to split off that flaky test into its own issue, especially if it requires a significant amount of work/code to fix.

taneliang avatar Dec 18 '20 07:12 taneliang