I ended up putting a separate call to testConn.create() in a module called my Jest Global setup hook so I could instruct Jest to refresh the database at the start of the test run by dropping the schema and recreating it from migrations by passing in dropSchema: true
The MyTestLifecycle module (in Typescript) just calls testConn.create(true) so that the schema is dropped at the start of all my tests and then re-created by running the migrations:
import { testConn } from './testConn';
export async function setup() {
await testConn.create(true);
}
Let me know when this is useful you!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I ended up putting a separate call to
testConn.create()in a module called my Jest Global setup hook so I could instruct Jest to refresh the database at the start of the test run by dropping the schema and recreating it from migrations by passing indropSchema: trueExample:
Then, if using TypeScript, add
globalSetupandglobalTeardownto yourjest.config.jsfile like so (at bottom):Then, in globalSetup.js you can call your TypeScript setup module by doing the following:
The MyTestLifecycle module (in Typescript) just calls
testConn.create(true)so that the schema is dropped at the start of all my tests and then re-created by running the migrations:Let me know when this is useful you!