I have a node.js application inside TypeORM's createConnection()
body:
// index.ts
import { createConnection } from "typeorm";
createConnection().then(async connection => {
// express app code here
}).catch(error => console.log(error));
Now, I wanted to write unit test cases using jest
and I wanted the connection to be available across the tests
// abc.test.ts
createConnection().then(async connection => {
describe('ABC controller tests', () => {
it('should test abc function1', async () => {
// test body does here
});
});
}).catch(error => console.log(error));
I have a few concerns:
- This is my first time working with TypeORM, so I don't have any hands-on experience on it
- It doesn't even work & throws
SyntaxError: Cannot use import statement outside a module
- It looks like a very ugly approach
- I wanted the connection making code at only one place, not in every test file but there is no entry point for tests like the app has
index.ts
How to globally createConnection() with TypeORM in unit tests?