0

How can I test this function wrapped in the React.memo , below is the function :

    const InternalDocuments = memo(
      forwardRef<FormikProps<BlocksTypes>, InternalDocumentsProps>(
        (
          {
            documentBlocks,
            loanId,
            updateZins,
            mainSetFieldValue,
            completedFieldRequiredRLA2,
            documentData,
          },
          formikRef,
        ) => {
          const [blocks, setBlocks] = useState<BlockBackend[]>([]);
          const classes = useStyles();
          const { setBalanceSheetValues, setBalanceSchufaValues } = useContext(DataContext);
    
          const mapDocumentBlocks = useCallback(
            () =>
             ...
            [],
          );
    
          const updateDataField = useCallback(
            (levels: indexObj, value: string, id: number) => {
             ....
            },
            [blocks],
          );
    
          useEffect(() => {
          }, []);
    
          return (
           <div>...</div>
          );
        },
      ),
    );
export default InternalDocuments;

This is my test below :

 it('should map document blocks', () =>{
    const { result } = renderHook(() => InternalDocuments())
    expect(typeof result.current.updateDataField).toBe('function')
  })

But I get this error :

 TypeError: (0 , _InternalDocuments.default) is not a function
4
  • Please provide a mvce, remove the unrelated code Commented Apr 14, 2022 at 3:30
  • Comeon @slideshowp2, so you mean you don't understand the code provided, it's actually minimal with key points Commented Apr 14, 2022 at 10:38
  • InternalDocuments is a component, why do you use renderHook? Commented Apr 14, 2022 at 10:56
  • Since memo is under hooks, I thought it would be so, I just needed guidance here Commented Apr 14, 2022 at 11:18

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.