fix: calling EntityManager.insert() with an empty array of entities (… · typeorm/typeorm@f8c52f3
1+import "reflect-metadata";
2+import {closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../utils/test-utils";
3+import {Connection} from "../../../src/connection/Connection";
4+import {Post} from "./entity/Post";
5+6+describe("github issues > #5734 insert([]) should not crash", () => {
7+8+let connections: Connection[];
9+before(async () => connections = await createTestingConnections({
10+entities: [__dirname + "/entity/*{.js,.ts}"],
11+subscribers: [__dirname + "/subscriber/*{.js,.ts}"],
12+schemaCreate: true,
13+dropSchema: true
14+}));
15+beforeEach(() => reloadTestingDatabases(connections));
16+after(() => closeTestingConnections(connections));
17+18+it("should not crash on insert([])", () => Promise.all(connections.map(async connection => {
19+const repository = connection.getRepository(Post);
20+await repository.insert([]);
21+})));
22+23+it("should still work with a nonempty array", () => Promise.all(connections.map(async connection => {
24+const repository = connection.getRepository(Post);
25+await repository.insert([new Post(1)]);
26+await repository.findOneOrFail({where: {id: 1}});
27+})));
28+});