Skip to content

Instantly share code, notes, and snippets.

@qunabu
Created April 19, 2020 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qunabu/4d151c9c0ace24290bb4942897e95397 to your computer and use it in GitHub Desktop.
Save qunabu/4d151c9c0ace24290bb4942897e95397 to your computer and use it in GitHub Desktop.
Strapi simple unit test
const request = require("supertest");
// function from gist file
const { setupStrapi } = require("./helpers/strapi");
// We're setting timeout because sometimes bootstrap can take 5-7 seconds (big apps)
jest.setTimeout(10000);
let app; // this is instance of the the strapi
beforeAll(async () => {
app = await setupStrapi(); // return singleton so it can be called many times
});
it("should respond with 200 on /heartbeat", async (done) => {
request(app.server) // app server is and instance of Class: http.Server
.get("/heartbeat")
.expect(200) // expecting response header code to by 200 success
.expect("Hello World!") // expecting reponse text to be "Hello World!"
.end(done); // let jest know that test is finished
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment