Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integration testing of React front end with Django REST backend

Tags:

Does anybody know how to do integration testing of a (React) frontend with Django REST backend. I was able to write functional tests for the frontend with Nightwatch.js and with a fake server API. I am also able to separately test Django REST API - Django offers a LiveServerTestCase that can start a test server for you with a test database and destroy it at the end. I'm wondering if it's possible to somehow use/setup Django's test server that can be called by the front end (i.e. Nightwatch tests). I'm open to other ideas on how I can approach this problem.

like image 722
foobar Avatar asked Apr 26 '17 14:04

foobar


People also ask

How do you integrate Django and Reactjs?

Setting up our React app to integrate with Django We'll also use the promise-based HTTP client Axios to make HTTP request calls to our Django API. Next, go to the src/index. js file and add the following import statement: import "bootstrap/dist/css/bootstrap.

Can we integrate Django and React?

We have successfully connected our Django backend to a react frontend. You will need the Django REST framework to create the APIs the react frontend application will make use of to get backend data.


1 Answers

It is always a bit tricky to integration test heavy client side javascript applications. My tool of choice for this scenario is to use Capybara - a nice Ruby DSL for interacting with web pages - together with a javascript enabled driver. I have used both webkitdriver and poltergeist succesfully. They are both headless so you can run tests in the background without disturbing browsers popping up. (The case with selenium....) There are issues with both in certain cases that I don't remember right now.

Since you are using Django you may want to do testing in Python. I would suggest looking for support for one of the two drivers mentioned above. Also the node.js community may have something useful for this.

like image 128
froderik Avatar answered Sep 23 '22 09:09

froderik