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

195
Vistas
In what order does Jest run its tests?

I'm writing some tests against a card game I made in JS using Jest.

I wrote two tests so far; one testing a deck of 52 cards are created and the other tests if the player is drawn two cards at the opening round:

const { Deck, Player} = require("./cardgame")
let deck = new Deck()
deck = deck.createDeck()
let player = new Player()
player.openinghand(deck)

test('Expects Deck to have 52 cards', () => {
    expect(deck.length).toBe(52);
});

test('Expects Players opening hand to have 2 cards', () => {
    expect(player.hand.length).toBe(2)
});

So when I run the test, only the second one passes. I understand why it's failing because the deck length is no longer equal to 52. Does Jest run all the tests simultaneously and not in the order that they're written? How would I get this to pass both tests?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Unit tests should be idempotent. Regardless of the order of execution and how many times it is executed, the result should be the same.

You need to make sure the test environment, test double, test data are independent for each test case.

From your code, it seems that those two test cases share one test data. This can lead to the potential risk that a test case modifying it will affect other test case.

about 4 years ago · Juan Pablo Isaza Denunciar
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