UNPKG

undeexcepturi

Version:

TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.

48 lines (36 loc) 1.07 kB
import { BeforeDelete, BeforeUpdate, Entity, MikroORM, PrimaryKey, Property, wrap } from '@mikro-orm/sqlite'; @Entity() export class A { @PrimaryKey() id!: number; @Property({ nullable: true }) name?: string; @BeforeUpdate() async beforeUpdate() { await wrap(this, true).__em!.flush(); } @BeforeDelete() async beforeDelete() { await wrap(this, true).__em!.flush(); } } describe('GH issue 493', () => { let orm: MikroORM; beforeAll(async () => { orm = await MikroORM.init({ entities: [A], dbName: ':memory:', }); await orm.schema.dropSchema(); await orm.schema.createSchema(); }); afterAll(() => orm.close(true)); test(`GH issue 493`, async () => { const a = new A(); await orm.em.persistAndFlush(a); a.name = 'test'; await expect(orm.em.flush()).rejects.toThrow('You cannot call em.flush() from inside lifecycle hook handlers'); orm.em.remove(a); await expect(orm.em.flush()).rejects.toThrow('You cannot call em.flush() from inside lifecycle hook handlers'); }); });