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

96
Vistas
Trying to mock a data return in a promise causes jest to timeout

So I have a function which is a promise and returns and array (either empty of full depending how the data comes back) I've mocked the data return how I've got it working previously, I've used the debugger to check the values and it is getting the mocked values, but it is just timing out before it resolves?

  it('works correctly when audience assigned', () => {
    fetchEssentialComplianceData(
      { includeAudienceAssigned: true },
      { id: 'userId' }
    );
    getAssignedLearning.mock.calls[0][1]([], {
      getUserAssignments: {
        results: [
          {
            content: {
              contentType: 'contentType',
              isOfficial: true,
              title: 'content title',
            },
            contentId: 'content id',
            dueDate: 'due date',
          },
        ],
      },
    });
    expect(getAssignedLearning).toHaveBeenCalledTimes(1);
    expect(getAssignedLearning).toHaveBeenCalledWith(
      {
        input: {
          userId: 'userId',
          pageNumber: 0,
          returnCount: 12,
          sort: [
            {
              type: 'dueDate',
              order: 'desc',
            },
            {
              type: 'dateCreated',
              order: 'desc',
            },
          ],
        },
      },
      expect.any(Function)
    );
    //TODO always times out before resolving?
    return expect(
      fetchEssentialComplianceData(
        { includeAudienceAssigned: true },
        { id: 'userId' }
      )
    ).resolves.toBe([]);
  });

I've tried different ways of writing it, making it its own function, tried

I wrote it like this which passed, but was a false pass.

    const result = fetchEssentialComplianceData(
      { includeAudienceAssigned: true },
      { id: 'userId' }
    )
    expect(result).resolves.toBe(['123'])

I also have the same function tested but with no data return (the request is never sent) and this works correctly, I've tried it with different values to make sure and it is right.

it('works correctly when not audience assigned', () => {
    fetchEssentialComplianceData(
      { includeAudienceAssigned: false },
      { id: 'userId' }
    );
    expect(getAssignedLearning).toHaveBeenCalledTimes(0);
    return expect(
      fetchEssentialComplianceData({ includeAudienceAssigned: false })
    ).resolves.toStrictEqual([]);
  });

I'm jsut really stumped now, I've clicked on all the links I could find with google and couldn't find anything that would work

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