Instead of writing unit tests directly you can use API contracts.
Spring Cloud Contracts- Java or Pact - Multiple languages supported (URL).
API contract will define the request and response style tests for establishing the API contracts.
Further Pact and Spring Cloud Contracts can be injected into the DevOps tool-chain to automate the entire process .
For JS :
Pact is compatible with Jest (Node), Mocha (JS), Karma (JS), Jasmine(JS)
Sample Pact Test :
With non specific response values :
When "creating a user with an invalid username"
POST /users { "username": "bad_username", ... }
Then
Response is 400 Bad Request
Response body is { "error": "<any string>" }
With Specific response values :
When "creating a user with a username containing numbers"
POST /users { "username": "us3rn4me", email: "...", ... }
Then
Expected Response is 400 Bad Request
Expected Response body is { "error": "username can only contain letters" }