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