fullstack-hy2020 / part2-notes

69 stars 180 forks source link

updated tests to match lesson text in branch part5-8 #78

Closed bambery closed 1 year ago

bambery commented 1 year ago

The code in the branches part5-8 through part5-11 has multiple tests that do not pass when I clone the repo, install the packages, and attempt to run the tests. The code that is in the branches does not match the lesson code, though the lesson claims it should match.

For example: https://github.com/fullstack-hy2020/part2-notes/blob/part5-8/src/components/Note.test.js is missing the line const user = userEvent.setup() which is shown in the lesson here: https://fullstackopen.com/en/part5/testing_react_apps#clicking-buttons-in-tests

The tests in the repo also do not use async/await, unlike the lesson.

I assume these tests are from an older way of doing things, but they no longer work. I only updated the tests in part5-8, but the issue remains in the branches through 5-11.

I discovered this because my tests started taking a very long time to run as I was doing lesson 5c, and I wanted to compare against the example code to make sure I wasn't doing something incorrectly. When I fixed the tests, I also needed to add long wait times to any of the tests using user-events and async/await, especially NoteForm.

I think it would be helpful to alert the student in the lesson that using the user-event library will make the test suite run very, very slowly, and that the timeout param will need to be added to tests using it.

In this branch, with the 3 test files and 7 total tests, I ran the cloned branch on my local machine and got the following run times: (I hit 'a' to rerun the tests within the runner)

  1. 23.181 s
  2. 22.7 s
  3. 35.398 s
  4. 24.839 s
  5. 26.041 s
  6. 34.142 s
  7. 25.361 s
  8. 32.79 s
  9. 23.021 s
  10. 34.775 s

I had a few runs take over 40s, and some under 20s. I changed nothing about these tests, so it is confusing why there is 10+ seconds of difference between runs. The tests that took the longest to run changed with each run.

Alternately, I'd love to hear that I did in fact configure something incorrectly, and that there is a way to make these simple tests run in a reasonable amount of time! Regardless of that, the code in this repo should be updated to match the lesson code.