Repository: typeorm/typeorm
File: test/functional/relations/lazy-relations/persistence/persistence-lazy-relations.test.ts (TypeScript)

Code before:
import "reflect-metadata"
import {
    closeTestingConnections,
    createTestingConnections,
    reloadTestingDatabases,
} from "../../../../utils/test-utils"
import { DataSource } from "../../../../../src/data-source/DataSource"
import { Post } from "./entity/Post"
import { expect } from "chai"
import { Category } from "./entity/Category"

describe("relations > lazy relations > persistence and hydration of bidirectional lazy relations", () => {
    let dataSources: DataSource[]
    before(
        async () =>
            (dataSources = await createTestingConnections({
                entities: [__dirname + "/entity/*{.js,.ts}"],
                enabledDrivers: ["mysql", "postgres"],
            })),
    )
    beforeEach(() => reloadTestingDatabases(dataSources))
    after(() => closeTestingConnections(dataSources))

    it("should persist successfully and return persisted entity", () =>
        Promise.all(
            dataSources.map(async (dataSource) => {
                // create objects to save
                const category1 = new Category()
                category1.name = "category #1"

                const post1 = new Post()
                post1.title = "Hello Post #1"
                post1.category = Promise.resolve(category1)
                expect(await post1.category).to.equal(category1)

                const category2 = new Category()
                category2.name = "category #2"

                const post2 = new Post()
                post2.title = "Hello Post #2"
                post2.category = Promise.resolve(category2)

                // persist
                await dataSource.manager.save(category1)
                await dataSource.manager.save(post1)

Review comment (suggestion):
If you're changing these lines, you might as well do:

```suggestion
    before(async () => {
        dataSources = await createTestingConnections({
            entities: [__dirname + "/entity/*{.js,.ts}"],
            enabledDrivers: ["mysql"], // we can properly test lazy-relations only on one platform
        })
    })
```
(since the return value is not needed)

Code after:
import "reflect-metadata"
import {
    closeTestingConnections,
    createTestingConnections,
    reloadTestingDatabases,
} from "../../../../utils/test-utils"
import { DataSource } from "../../../../../src/data-source/DataSource"
import { Post } from "./entity/Post"
import { expect } from "chai"
import { Category } from "./entity/Category"

describe("relations > lazy relations > persistence and hydration of bidirectional lazy relations", () => {
    let dataSources: DataSource[]
    before(async () => {
        dataSources = await createTestingConnections({
            entities: [__dirname + "/entity/*{.js,.ts}"],
            enabledDrivers: ["mysql", "postgres"],
        })
    })
    beforeEach(() => reloadTestingDatabases(dataSources))
    after(() => closeTestingConnections(dataSources))

    it("should persist successfully and return persisted entity", () =>
        Promise.all(
            dataSources.map(async (dataSource) => {
                // create objects to save
                const category1 = new Category()
                category1.name = "category #1"

                const post1 = new Post()
                post1.title = "Hello Post #1"
                post1.category = Promise.resolve(category1)
                expect(await post1.category).to.equal(category1)

                const category2 = new Category()
                category2.name = "category #2"

                const post2 = new Post()
                post2.title = "Hello Post #2"
                post2.category = Promise.resolve(category2)

                // persist
                await dataSource.manager.save(category1)
                await dataSource.manager.save(post1)
                await dataSource.manager.save(category2)