Error following unit testing guide

System Information
  • Strapi Version: 4.15.4, 4.15.2, 4.10.8:
  • Operating System: MacOS 13.0:
  • Database: PosgreSQL / sqlite3:
  • Node Version: v20.5.1:
  • NPM Version: 9.8.0:
  • Yarn Version:

I followed the guide at Testing | Strapi Documentation up to and including the headline Test a Strapi Instance Testing | Strapi Documentation . When running the test, I get the following error:

During setup I received the error:

TypeError: Cannot destructure property ‘client’ of ‘db.config.connection’ as it is undefined.

And during cleanUp I received the error:

TypeError: Cannot read properties of undefined (reading ‘connection’)

During development, I am using postgres, however, the test database configuration is set to sqlite according to the guide. I am using TypeScript. The errors were observed with strapi version 4.15.2, 4.15.4 and 4.10.5.

Does anyone know how to fix this?

1 Like

I was not able to fix the problem with a strapi setup using typescript. Among other things, I tried out using better-sqlite3 instead of sqlite3 and I followed the resources Installation | ts-jest and Jest - TypeScript Deep Dive to use ts-jest.

I switched to javascript instead of typescript and now it works.

I gave it another try and the fix was embarrassingly simple. I checked at TypeScript | Strapi Documentation and found that the code from Testing | Strapi Documentation had to be adjusted in that line 8 of tests/helpers/strapi.js needs to be changed from
await Strapi().load();
await Strapi({ distDir: "./dist" }).load();.

1 Like