Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

156
Vistas
Why is my jest test of a simple boolean statement taking much longer than it does console?

I have a function - let's call it generateMove that returns a random value on a board of 10 x 10. There are 100 possible values. generateMove should check that its random move isn't taken before returning its chosen move.

In console it is very easy for me to test this by calling the function 99 times and making an array of all the moves.

ie.

const alreadyTaken = [];
for (let i=0;i<99;i++) {
    alreadyTaken.push(generateMove());
}

Then I can take one final move by calling generateMove again and assigning it to a variable, ie. const last = generateMove();

To check if the last move is included in the array of the other 99 possible values I use const isIncluded = alreadyTaken.includes(last) which if I console log it correctly logs false

I am trying to do this exact same thing in a Jest test function ie.

test('ai does not hit places that were already hit', () => {
        const alreadyPlayed = [];
        for (let i=0;i<99;i++) {
            alreadyPlayed.push(generateMove());
        }
        const last = generateMove();
        const isIncluded = alreadyPlayed.includes(last);
        expect(isIncluded).toEqual(false);
    })

which should be fairly simple right? all of the heavy lifting has been done and the variable isIncluded should be a simple boolean falsewhich is the only value matching Jest has to accomplish but it keeps crashing and timing out on test.

I've tried putting the loop and other code outside of the 'test' function and it doesn't help - all of the code is inside a describe bloc however if that is relevant.

Does anyone know why Jest is crashing? Can it not handle for-loops etc. within test suites?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda