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

146
Visualizações
Create a jest test to fail an async function which does not use await
async function isContentUser (userEmail, studentStatus) {
  const hasContentAccess = getContentCreatorAccess()
  const hasContentStudentStatus = studentStatus === CONTENT

  return hasContentStudentStatus || hasContentAccess
}

async function getContentCreatorAccess () {
  const { contentCreatorAccess } = await api.getContentCreatorPermission()

  return contentCreatorAccess
}

As you can see in isContentUser function, we're not awaiting getContentCreateAccess, but the below existing test pass, because hasContentAccess in the return value is a promise and we're awaiting the promise in the test.

And I want to create a PR which adds await before getContentCreatorAccess call, how can I come up with a test which works with await but not in the current code.

  it(`should return true if studentStatus is not Content but user has content permission`, async () => {
    api.getContentCreatorPermission.mockResolvedValue({
      contentCreatorAccess: true
    })

    expect(await isContentUser('email@gmail.com', 'Audit')).toBe(true)
  })
about 4 years ago · Juan Pablo Isaza
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