React Testing Library Setup in the SPA Widget
In this lesson, we'll see how to make a job for the React Testing Library on Educative. Let's begin! :)
We'll cover the following
Dockerfile
We use the Dockerfile we made in the previous lessons, as shown below:
FROM node:8.15RUN npm -g install eslintRUN npm -g install eslint-config-airbnbRUN npm install -g eslint-plugin-importRUN npm install -g eslint-plugin-jsx-a11yRUN npm install -g eslint-plugin-reactRUN npm install -g prettierRUN npm install -g --save-dev jestRUN npm install -g --save-dev @testing-library/react
As you can see from the code snippet above, we install the react testing library in line 12 :
RUN npm install -g --save-dev @testing-library/react
via the node:8.15 image in line 1.
Note: In case you are only interested in installing and setting up the RTL, you need only have lines 1 and 12 in your Dockerfile. Which will then look as follows:
FROM node:8.15
RUN npm install -g --save-dev @testing-library/react
Dockerjob
Now, all we need is a Docker Job to make multiple RTL tests work in the SPA widget. Here are the Docker Job settings:
Job Name: RTLInputFileName: foo (can be anything)Run Script: (not needed)Run in Live Container: TrueApp port: 3000Start Script: cd /usercode && npm i && npm test
From there, navigate to a lesson, add a new SPA widget, select the above Docker Job in the dropdown menu, and add a GitHub Repo for testing. Click Run and it should work.
For an example, see the Core-JS library at https://github.com/zloirock/core-js…
That’s a wrap! We hope this guide proved helpful for you.
Happy Course Making From All of Us at Educative! 🎉