mardi 27 mars 2018

jest: handle errors during setup of custom test environment

I want to run my integration tests using jest. To setup the database connection and what not, I'm also using a custom TestEnvironment through the jest's config option testEnvironment.

const NodeEnvironment = require('jest-environment-node');
const insert = require('../.db/insert-dummy-data');

class CustomEnvironment extends NodeEnvironment {
  async setup() {
    await super.setup();
    await insert();
  }

  async teardown() {
    await super.teardown();
  }

  runScript(script) {
    return super.runScript(script);
  }
}

If the insert() throws an error b/c the DB connection couldn't be established for example, the different test-suites fail, but the whole command hangs and doesn't exit. Just setup() is called but not teardown(). What is the right way to handle errors in the setup of the custom test-environment?

Aucun commentaire:

Enregistrer un commentaire