Test-Driven Node Postgres Knex Dockerized
Three days ago I started a short tutorial on how to write a test-driven Node.js web API with PostgreSQL database.
The excellent blog post is from 2016, but it’s still useful.
I used Docker to build the application. If you want to see the example application as a dockerized Node.js/Express.js program, you can take a look at my GitLab repository.
The repository also uses GitLab CI to build the container and run the tests with Mocha.
Test Redirect With Jest, React-Router and React-Testing-Library
You’ve set up react-testing-library with Jest and react-router. You want to check that a component successfully redirects to another page. But how?
Your React application comes with a protected route. If a user is not authenticated, the app should redirect the user to the login screen.
You’ve managed to set up react-router-dom for your component.
For example, here’s an excerpt from a UserStatus.jsx component that only an authenticated user should be able to access:
Fix Import React Renderer With Jest Error
A few days ago, I updated a React application that uses Jest and Enzyme for testing.
The new tests yielded errors like cannot find module ‘react-test-renderer’.
Solution: Install react-test-renderer and enzyme-to-json as dev dependencies, and re-factor tests to use enzyme-to-json.
npm i –save-dev react-test-renderer enzyme-to-json In your package.json file, add the serializer to your jest config:
{ "jest": { "snapshotSerializers": [ "enzyme-to-json/serializer" ] } } Example test file before update: