Skip to content

Commit 7002383

Browse files
committed
test: add and configure Jest for running tests of React components
The following dependencies have been installed: - jest: the testing framework - babel-jest: integration for Babel (https://jestjs.io/docs/en/getting-started#using-babel), otherwise tests fail with "Support for the experimental syntax 'jsx' isn't currently enabled" - @testing-library/react: the library for testing React components - @testing-library/jest-dom: useful matches for inspecting DOM - react and react-dom: in order to import React in tests All the dependencies were installed by the command: ./mvnw -Pfrontend frontend:npm -Dfrontend.npm.arguments='install --save-dev jest babel-jest @testing-library/react @testing-library/jest-dom [email protected] [email protected]' In order to execute (or execute and watch) the tests, run: ./mvnw -Pfrontend frontend:npm -Dfrontend.npm.arguments='test' or ./mvnw -Pfrontend frontend:npm -Dfrontend.npm.arguments='run watch-test' Alternatively, it's possible to use npx: cd src/main/frontend npx jest or npx jest --watch Note that at the moment of this commit, there is no tests yet, so the previous command will fail. While I marked React as an external (see webpack.config.js), all bundles got additional 5 Kb and I couldn't figure out why. Perhaps, it's how it should work, but I'm not sure as I expected that bundles size will stay the same. Useful links: - https://jestjs.io - https://github.com/testing-library/react-testing-library - https://github.com/testing-library/jest-dom - https://www.newline.co/@dmitryrogozhny/how-to-start-using-react-testing-library--0e7695e8 Part of #1484
1 parent 9c6772f commit 7002383

File tree

6 files changed

+6296
-1540
lines changed

6 files changed

+6296
-1540
lines changed

pom.xml

+6-1
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,12 @@
645645
<!-- Redefine default value from spring-boot-dependencies -->
646646
<postgresql.version>9.4.1212.jre7</postgresql.version>
647647

648-
<!-- Don't forget to update version in the ResourceUrl class and in the src/main/webapp/WEB-INF/views/series/info.html -->
648+
<!--
649+
Don't forget to update version in the following places:
650+
- ResourceUrl class
651+
- src/main/webapp/WEB-INF/views/series/info.html
652+
- src/main/frontend/package.json
653+
-->
649654
<react.version>16.8.6</react.version>
650655

651656
<resources.plugin.version>3.2.0</resources.plugin.version>

src/main/frontend/babel.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Note that this configuration is used by Webpack (babel-loader) and Jest
12
module.exports = {
23
presets: [ "@babel/preset-react", "@babel/preset-env" ]
34
};

src/main/frontend/jest.config.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// @todo #1484 Document Jest usage
2+
module.exports = {
3+
// https://jestjs.io/docs/en/configuration#watchman-boolean
4+
"watchman": false
5+
}

0 commit comments

Comments
 (0)