DEV Community

Discussion on: Unit testing NestJS with Typeorm in memory

Collapse
 
dariansampare profile image
Darian Sampare

Pretty nice trick for testing individual service queries without mocking! Any clue if this approach works for Postgres?

Collapse
 
mangelov profile image
Mikhail Angelov

I made a simple lib, wich can help with it github.com/mikhail-angelov/nestjs-...

Collapse
 
bassochette profile image
Julien Prugne

From my researches you can't run postgres in memory.
This solution, is not optimal even with mysql more a trick to simplify a bit testing and ci setup.

Imo, you should setup a test db and reset it between tests. You'd be able to test all those neat postgres features. It's more complicated and add some ci setup but should be worth it.

Collapse
 
wh1t3h47 profile image
Antônio Martos Harres

You can try pg-mem and it can also by used with typeORM
github.com/oguimbal/pg-mem/wiki/Li...

Collapse
 
bassochette profile image
Julien Prugne

Looks like what I am looking for to enhance my tests.
I'll give it a try in the evening.
Thanks mate