How to test an export function which has req as parameter in react

I’m really new to react and I’ve given a code to test.

export function getServerSideProps({ req }) {
  return {
    props: {
      profit: req.properties.profit,
    },
  };
}

export default function DailyProfit(props) {
  const [pageErrors, setPageErrors] = useState([]);

  return (
    <PageTemplate
      heading="Profit page"
      backLink="/"
      errors={pageErrors}
    >
      <HmpoDatePicker {...props} errorCallback={setPageErrors} />
    </PageTemplate>
  );
}

How can I test the first export function getServerSideProps I’m really stuck and any help will be appreciated. Thanks

Answer

import {getServerSideProps} from 'file_name';

describe('getServerSideProps', () => {
  test('returns properties from request properties', () => {
    const request = {
      properties: { profit: 'someProfit' }
    }
    expect(getServierSideProps({req: request}).props.profit).toEqual(request.properties.profit);
  }); 
});

You just call the function with mocked argument so that you are sure that getServerSideProps function correctly parses the given object.

Note that above example is written used the jest test runner