Jest preset that simplifies MySQL database setup for integration testing. Version 2.0.2 requires Node >=16 and peer dependencies jest 29.x.x and mysql 2.x.x. Offers schema import, automatic database creation, optional truncation after tests, and custom setup hooks. Provides a global db connection for querying within tests. Differentiates from alternatives by being a full preset rather than a library, streamlining configuration via jest-mysql-config.js.
npm install jest-mysqlNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Configure Jest preset, set MySQL connection options, and use global.db to run queries in tests.
Replace mysql with mysql2 as peer dependency. Note: jest-mysql may not be compatible with mysql2 directly; consider using mysql2 and adapt connection options.
Remove testEnvironment from jest config if present.
Wrap queries in Promises or use util.promisify(global.db.query).bind(global.db).
Upgrade Node to >=16 and jest to 29.x.x.
npm install jest-mysql --save-dev
Use preset: 'jest-mysql' (string) in jest config.
Check jest-mysql-config.js for correct databaseOptions and ensure MySQL server is running.
Verify username, password, host, and port in jest-mysql-config.js.