WordPress Redux Store Middleware Testing with Jest
October 02, 2021Jest is a Javascript Testing Framework. It focuses on simplicity according to their webpage. Jest integrates well with most popular frameworks and libraries. In this article we will create a simple Redux Store Middleware inside a WordPress Installation. Then write tests in Jest to test the implementation.
First, a WordPress REST API should be created to handle requests from the app. Then a Redux Store should be created using Redux Toolkit. We can create a redux store without Redux Toolkit. But we have to use a lot of boilerplate code. Middleware can be used to intercept the dispatched actions before reaching the store. Middleware can also dispatch additional actions if necessary. Let’s create 3 simple middleware. Finally, let’s write some tests with Jest for the store implementation.
Read more about Jest and Redux Store Testing