Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

194
Visualizações
Jest test fails when environment is configured with webpack-hot-middleware

So I'm running a very basic Jest test to test if one of my routes returns a 200.

import request from 'supertest';
import app from './../app';

describe('GET /', () => {
  it('should render properly', async () => {
    await request(app).get('/api/testing').expect(200);
  });
});

This was working perfectly then I configured webpack-hot-middleware and it seems to break at line 2 where I import app.

TypeError: setInterval(...).unref is not a function

  at createEventStream (node_modules/webpack-hot-middleware/middleware.js:50:17)
  at webpackHotMiddleware (node_modules/webpack-hot-middleware/middleware.js:12:21)
  at Object.<anonymous> (server/app.js:62:73)
  at Object.<anonymous> (server/test/routes.test.js:2:38)

If I remove the following code from my app.js the tests all run fine.

  app.use(middleware);
  app.use(webpackHotMiddleware(compiler));
  app.get('*', (req, res) => {
    res.write(middleware.fileSystem.readFileSync(path.join(__dirname, '../dist/index.html')));
    res.end();
  });

Has anyone configured Jest for webpack-hot-middleware? I'm kind of lost because I feel like I've tried everything.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

You must set testEnvironment Jest config option to node. unref() exists in Node.js only.

over 4 years ago · Santiago Trujillo Relatório

0

By adding a @jest-environment docblock at the top of the file, you can specify another environment to be used for all tests in that file, refer to jest documentation

/**
 * @jest-environment jsdom
 */

import request from 'supertest';
import app from './../app';

describe('GET /', () => {
  it('should render properly', async () => {
    await request(app).get('/api/testing').expect(200);
  });
});
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda