mirror of
https://github.com/strapi/strapi.git
synced 2025-11-29 16:41:19 +00:00
add some adittional tests
This commit is contained in:
parent
ec9150b1d8
commit
65660d18e1
@ -9,6 +9,7 @@ jest.mock('../connection', () =>
|
|||||||
rollback: jest.fn(),
|
rollback: jest.fn(),
|
||||||
};
|
};
|
||||||
return {
|
return {
|
||||||
|
...trx,
|
||||||
transaction: jest.fn(async () => trx),
|
transaction: jest.fn(async () => trx),
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
@ -64,6 +65,19 @@ describe('Database', () => {
|
|||||||
const db = await Database.init(config);
|
const db = await Database.init(config);
|
||||||
const result = await db.transaction(async () => 'test');
|
const result = await db.transaction(async () => 'test');
|
||||||
expect(result).toBe('test');
|
expect(result).toBe('test');
|
||||||
|
expect(db.connection.commit).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('rollback is called incase of error', async () => {
|
||||||
|
const db = await Database.init(config);
|
||||||
|
try {
|
||||||
|
await db.transaction(async () => {
|
||||||
|
throw new Error('test');
|
||||||
|
});
|
||||||
|
} catch {
|
||||||
|
/* ignore */
|
||||||
|
}
|
||||||
|
expect(db.connection.rollback).toHaveBeenCalledTimes(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw error', async () => {
|
it('should throw error', async () => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user