Skip to content

Commit

Permalink
Fixing unit testing docs for Strapi 5 (#2308)
Browse files Browse the repository at this point in the history
* Update the first message to remove v4 docs and to let users know that these docs are only for JS strapi projects

* Remove the testEnvironment key because it's already set to the Jest default

* Update setupStrapi function for Strapi 5

* Remove the unneeded fs module import at the top of this example

* It's important to add this so that the correct database config file is used.

* Change callout at the top of the page
  • Loading branch information
kasonde authored Dec 9, 2024
1 parent 4951b37 commit ba3e2ce
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions docusaurus/docs/dev-docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ tags:

# Unit testing

:::strapi
The Strapi blog has a tutorial on how to implement [API testing with Jest and Supertest](https://strapi.io/blog/automated-testing-for-strapi-api-with-jest-and-supertest) and [how to add unit tests to your Strapi plugin](https://strapi.io/blog/how-to-add-unit-tests-to-your-strapi-plugin).
:::info
Currently, our docs are only for Javascript projects that wish to have unit testing setup. We will update our docs soon as soon as we have the Typescript equivalent code samples available.
:::

In this guide we will see how you can run basic unit tests for a Strapi application using a testing framework.
Expand Down Expand Up @@ -74,7 +74,6 @@ and add those lines at the bottom of file
".tmp",
".cache"
],
"testEnvironment": "node"
}
```

Expand Down Expand Up @@ -119,7 +118,7 @@ let instance;

async function setupStrapi() {
if (!instance) {
await Strapi().load();
await Strapi.createStrapi().load();
instance = strapi;

await instance.server.mount();
Expand Down Expand Up @@ -153,7 +152,6 @@ module.exports = { setupStrapi, cleanupStrapi };
We need a main entry file for our tests, one that will also test our helper file.

```js title="path: ./tests/app.test.js"
const fs = require('fs');
const { setupStrapi, cleanupStrapi } = require("./helpers/strapi");

beforeAll(async () => {
Expand All @@ -169,7 +167,7 @@ it("strapi is defined", () => {
});
```

Actually this is all we need for writing unit tests. Just run `yarn test` and see a result of your first test
Actually this is all we need for writing unit tests. Just run `NODE_ENV=test yarn test` and see a result of your first test

```bash
yarn run v1.13.0
Expand Down

0 comments on commit ba3e2ce

Please sign in to comment.