lundi 26 novembre 2018

How to dynamically load tests suites in JEST

I am trying to dynamically load my test suites with async data which is available only once beforeAll is complete. Here is the code for a better reference.

Here is my initial setup:

let server;

beforeAll(() => {
  server = await createServer();
})

afterAll(() => {
  closeServer();
});

fs.readDirSync('./tests')
  .forEach(filename => {
    require(`./${filename}`)(server);
  });

And here is how a sample test suite looks like

module.exports = server => {
  describe('test', () => {
    // do something with the server
  })
}

I know I can use global obj, but really want to find a way to dynamically inject the server

Aucun commentaire:

Enregistrer un commentaire