I’m using express, mocha, supertest and typeorm.
Mocking the database is fucking black magic. So I gave up and simply use an in memory SQLite db and add some records in the test body for my API to fetch and return so I can test.
I’d like the db to basically get nuked and recreated after every test.
So I use “afterEach” to close the connection and create a new one.
No matter what I do, when I call the api endpoint using supertest it tells me my DB connection is closed.
You’re thinking maybe the previous test didn’t reopen it or something. But there only one test.
It’s like it’s closing it _before_ the test runs. As if afterEach is not waiting on the result from supertest (yes I awaited).
I spent a _whole day_ today trying to understand just what the fuck is going on.
Gimme goroutines _any day_.