Fellows, I read this topic but still didn't get it how to apply the solution on my code since I am using a middleware. Tried so many things but still didn't get it, keep receiving this message when test try to render the component.
test.js
it("should redirect to envio-de-documentos page when upload button is clicked and step belongs to checklist 1 phase", async () => {
await act(async () => {
renderComponent(
<ProposalActions // Error happens here
isDocumentsLoading={false}
state={ENVIO_DOCS_IMOVEL_03}
objectName="re_financing_simulator_proposal_status_pre_proposal_sent"
tracking={() => {}}
id={123456}
/>
)
})
fireEvent.click(
screen.getByText("Enviar Documentos", {
selector: "button",
exact: false,
})
)
await waitFor(() =>
expect(navigate).toHaveBeenCalledWith(routes.UPLOAD_DOCUMENTS_PAGE)
)
})
return from the component I'm rendering (ProposalActions.js)
return (
<Container>
<UploadDocuments
fluid
label={buttonStatus.label}
icon={buttonStatus.icon}
onClick={() => {
dispatch(startDocumentsUpload({ id, step })) // <-- Error is happening here
if (
objectName ===
"re_financing_simulator_proposal_status_pre_proposal_approved"
)
tracking.send("click", "btn_send_docs")
}}
isLoading={isDocumentsLoading}
/>
</Container>
)
actions.js - where startDocumentsUpload lives
export const startDocumentsUpload = createAsyncThunk(
"proposal/startDocumentsUpload",
async ({ id, step }, { dispatch }) => dispatch(fetchDocuments({ id, step }))
)
actions.js - where fetchDocuments lives as well
export const fetchDocuments = createAsyncThunk(
"proposal/fetchDocuments",
({ id, step }) => api.getProposalDocuments(id, step),
{ condition: id => !!id, dispatchConditionRejection: true }
)
Then in my reducer.js
I have a fetchDocuments.pending
, fetchDocuments.rejected
, and fetchDocuments.fulfilled
.
Now back to startDocumentsUpload
action, when it's fulfilled I have this:
builder.addCase(startDocumentsUpload.fulfilled, (state, { payload }) => {
const target =
payload.meta.arg.step === 1
? routes.UPLOAD_DOCUMENTS_PAGE
: routes.LEGAL_ASSESSMENT_PAGE
state.currentPath = navigate(
`${target}?id=${payload.id}`,
state.currentPath
)
})
So this redirect/navigation to routes.UPLOAD_DOCUMENTS_PAGE is what I'm trying to test.
I know this code is quite confusing, I inherited this and I'm still trying to understand what's happening :( Please help