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
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 Respostas
Responde à pergunta

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 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