DEV Community

Discussion on: Tests with Jest and TypeORM

Collapse
 
morcegon_22 profile image
Renan Andrade

Hello dude!
First of all, thank you by the great article, it help me a lot.
I've noticed that in the clear function you put an await function inside a forEach iterator, but in this case the promise will not work properly.
I solve this issue using the map instead the forEach and placing the map result inside a Promise.all(). This works great to me.

Collapse
 
sadra profile image
Sadra Isapanah Amlashi • Edited

Can you put your example here please?

Collapse
 
samrith profile image
Samrith Shankar

Here you go:

const entityDeletionPromises = entities.map((entity) => async() => {
  const repository = connection.getRepository(entity.name);
  await repository.query(`DELETE FROM ${entity.tableName}`);
});
await Promise.all(entityDeletionPromises);
Enter fullscreen mode Exit fullscreen mode
Thread Thread
 
jackbilestech profile image
jack-biles-technology • Edited

I'm currently using typeorm 0.2.31 and they allow for repo.clear() to truncate / drop the table