Repository: typeorm/typeorm
File: test/functional/repository/find-options-locking/find-options-locking.ts (TypeScript)

Code before:
                            lock: { mode: "pessimistic_write" },
                        }).should.not.be.rejected,
                    ])
                })
            }),
        ))

    it("should attach pessimistic read lock statement on query if locking enabled", () =>
        Promise.all(
            connections.map(async (connection) => {
                if (
                    DriverUtils.isSQLiteFamily(connection.driver) ||
                    connection.driver.options.type === "cockroachdb" ||
                    connection.driver.options.type === "sap" ||
                    connection.driver.options.type === "spanner"
                )
                    return

                const executedSql: string[] = []

                await connection.manager.transaction((entityManager) => {
                    const originalQuery = entityManager.queryRunner!.query.bind(
                        entityManager.queryRunner,
                    )
                    entityManager.queryRunner!.query = (...args: any[]) => {
                        executedSql.push(args[0])
                        return originalQuery(...args)
                    }

                    return entityManager.getRepository(PostWithVersion).find({
                        where: { id: 1 },
                        lock: { mode: "pessimistic_read" },
                    })
                })

                if (DriverUtils.isMySQLFamily(connection.driver)) {
                    expect(executedSql[0].indexOf("LOCK IN SHARE MODE") !== -1)
                        .to.be.true
                } else if (connection.driver.options.type === "postgres") {
                    expect(executedSql[0].indexOf("FOR SHARE") !== -1).to.be
                        .true
                } else if (connection.driver.options.type === "oracle") {
                    expect(executedSql[0].indexOf("FOR UPDATE") !== -1).to.be
                        .true
                } else if (connection.driver.options.type === "mssql") {
                    expect(
                        executedSql[0].indexOf("WITH (HOLDLOCK, ROWLOCK)") !==
                            -1,
                    ).to.be.true
                }
            }),

Review comment (suggestion):
This test should have used spies + called with argument. I'm not very familiar with Chai/SinonJS, so I'd rather not change it myself.

Code after:
                            where: { id: 1 },
                            lock: { mode: "pessimistic_write" },
                        }).should.not.be.rejected,
                    ])
                })
            }),
        ))

    it("should attach pessimistic read lock statement on query if locking enabled", () =>
        Promise.all(
            connections.map(async (connection) => {
                if (
                    DriverUtils.isSQLiteFamily(connection.driver) ||
                    connection.driver.options.type === "cockroachdb" ||
                    connection.driver.options.type === "sap" ||
                    connection.driver.options.type === "spanner"
                )
                    return

                const executedSql: string[] = []

                await connection.manager.transaction((entityManager) => {
                    const originalQuery = entityManager.queryRunner!.query.bind(
                        entityManager.queryRunner,
                    )
                    entityManager.queryRunner!.query = (...args: Parameters<QueryRunner['query']>) => {
                        executedSql.push(args[0])
                        return originalQuery(...args)
                    }

                    return entityManager.getRepository(PostWithVersion).find({
                        where: { id: 1 },
                        lock: { mode: "pessimistic_read" },
                    })
                })

                if (DriverUtils.isMySQLFamily(connection.driver)) {
                    expect(executedSql[0].indexOf("LOCK IN SHARE MODE") !== -1)
                        .to.be.true
                } else if (connection.driver.options.type === "postgres") {
                    expect(executedSql[0].indexOf("FOR SHARE") !== -1).to.be
                        .true
                } else if (connection.driver.options.type === "oracle") {
                    expect(executedSql[0].indexOf("FOR UPDATE") !== -1).to.be
                        .true
                } else if (connection.driver.options.type === "mssql") {
                    expect(
                        executedSql[0].indexOf("WITH (HOLDLOCK, ROWLOCK)") !==
                            -1,
                    ).to.be.true
                }