Function bindReplaySequelizeModels

  • Parameters

    Returns Sequelize

    Description

    Test-setup helper that binds Sequelize models to an OFFLINE Sequelize instance in replay mode — the constructor performs no I/O, so no live DB is required.

    Why: in replay the original connect() is replayed from the snapshot, so the model is never bound to a Sequelize instance and its isInitialized flag stays false — the original static build() would throw ModelNotInitializedError during replay reconstruction (see rebuildInstance).

    The binding runs with the global mode temporarily switched to 'off' and restored afterwards, because Model.init() internally invokes wrapped statics (e.g. getTableName) which must NOT route into a replay lookup during setup.

    No-op (returns undefined) outside replay mode.

    Example

    import { bindReplaySequelizeModels } from '@biorate/unimock';

    beforeAll(async () => {
    // offline-биндинг, без I/O; вернёт undefined вне replay
    bindReplaySequelizeModels(TestModel, OtherModel);
    });