For this post, I am going to reflect on the pull requests that I made for Release 0.4. Now, while I do not need to make this reflection, I am going to do it just because I want to talk about what I did for trying to create tests for app that run through React, and the huge amounts of trouble that I went through just to create such simple pull requests. You can view each of my blog posts on create the tests here:
Now, when trying to create these test, I had no idea what I was getting into. For the most part, I am not great at creating checks for errors within code. I usually just read through the code and try to determine what the problem being cause is based on the error messages and solve the problem myself. However, for this, I have had very little experience with React apps and creating tests for those apps, which is why I wanted to take on these pull requests, since I would have a reason to learn about testing for error, and it would help me get over my Achilles’ heel of testing. I never expected how difficult it would be to make even the simplest of tests.
I spent the most time on the Curated-tv-and-film pull request, as it was the one I started with, and was the one that I wanted to figure out how to work on the most. I skimmed through the code, and after noticing how the toggleFilter
event just changes a single state from false to true and shows the filter bar, I figured that would be the easiest place to start. It seemed simple in concept, just retrieve the state of the showFilters
value, run a event once, and check the showFilters
value again to see if it had changed. The real problem was trying to find information on how to check for changes to state. I went straight to the official document for testing React apps, but there was nothing that I could use there. I then went on to the document on Test Utilities for React, but I still couldn’t find anything on testing for state there. After jumping from post to random post, I finally stumbled onto a post that explicitly has the title that it was testing for state, but that was after several hours of testing what seems like it would work, and trying everything that I could possibly find. The post it located here, and it was just a random post that was not connected to the official documents at all.
Searching for the a way to run an event was even more difficult. I could not figure out for the life of me how to to emulate running an event. The biggest issue was that the events were not declared as a method within the app, but instead were a lambda that was given an event. So, instead of toggleFilter(), it was instead toggleFilter = () = > {}. Since ever test that I could find online was for a method instead of a lambda, I could not find a single thing to help me figure out what to do to run the lambda. I eventually had to ask the owner how I should go around doing it, and the owner quickly informed me of what I to run, which was wrapper().instance().method(). The worst part was when I pulled the current version of the repository, my simple test that barely had anything within it stopped working, and I was suddenly back at square one after all that work.
After this. I kept searching to see whether I could figure out what the new issue that arouse was, to no avail. After so much time spent trying to figure out errors and getting the tests working, I just gave up, and made a request to check to see whether the HTML div was being rendered correctly. While simple, it still is an important part of the app to check, because if it fails that app will not show anything at all, but it was not even close to as much as I would have liked to do. I really wish there was more documentation on creating tests for React, especially for problems that will occur when attempting to create a test, since there was not much information to go on that I could use to determine how to solve my problem.
The lack of information became the biggest problem when working on the Creative-Collab repository. I couldn’t even get shallow rendering working with the app, and had absolutely no idea why. When it turned out that the problem was because of the React-Quill component that I could not do anything about, that was one of the worst times of my life, since I spent so much time trying to find the solution to the problem and it turns out that I could not do anything about it. Not mentioning that I planned to create tests for the repository was my fault, as another student went on and created tests for the components, but they were not part of the tests that I was planning to create, so it was more or less fine. The biggest problem was that I had spent so much time trying to figure out how to shallow render, that I have very little time left to work on create normal tests for the repository. Since I had no way of solving the shallow rendering problem, I could not even attempt to create tests the same way that did for the previous repository, and since I could not use mount I was couldn’t even mount the repository correctly. This forced me to simply use the same tests that I used for the Curated-tv-and-film, which bothered me quite a bit since it was not nearly as complex as I would have liked.
The only part of this release that was not that bad was updating tests for the python exercises. The problem with running the exercises was troublesome, but quickly resolved after asking the owner of the repository about it. Once that problem was solved, updating the test was simple. All I needed to do was look at the previous code and see what had changed, and make the changes necessary to accommodate those changes.
This release was very dissatisfying for me. After all that work, several hours of searching online for the solution to the errors that I was running into, all I could do was create simple tests and push those to the repository, since those were all I could get working. I hope that either documentation on testing React apps will grow in the future, or I get better at searching for issue solutions on Google.