drizzle-orm
drizzle-orm copied to clipboard
[BUG]: Unable to insert when using jest fake timers
What version of drizzle-orm
are you using?
0.25.4
What version of drizzle-kit
are you using?
No response
Describe the Bug
If you try to insert data while fake timers are in use, the data is never inserted and the test timeout.
import {beforeAll, afterAll, jest} from "@jest/globals";
import {datetime, int, mysqlTable, text} from "drizzle-orm/mysql-core";
import {drizzle, MySql2Client, MySql2Database} from "drizzle-orm/mysql2";
import {getDrizzleClient} from "src/test-utils/db-utils";
export const booksTable = mysqlTable('books', {
id: int('id').autoincrement().primaryKey(),
title: text('title').notNull(),
createAt: datetime('createdAt', { mode: 'date' }).notNull(), // the presence of a datetime field is unrelated, I've tested
});
describe('Demo', () => {
let drizzleClient: MySql2Client;
let db: MySql2Database;
beforeAll(async () => {
drizzleClient = await getDrizzleClient();
db = drizzle(drizzleClient);
jest.useFakeTimers(); // Comment this line, and it works !
});
afterAll(async () => {
await drizzleClient.end();
});
it('should insert data', async () => {
await db.insert(booksTable).values({
title: "Never happening",
createAt: new Date(),
});
});
});
Expected behavior
No response
Environment & setup
No response
jest mocks too much by default in its timers. try mocking out just the parts you really need, that should help (jest timer mocking supports granular configuration). had same issue with fastify init breaking, this helped.
This issue is not related to drizzle-orm