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

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