title: unit test in Nodejs using Jest
body: <p>I have a method in controller, as below:</p>
  
  <pre><code>    import { calcu } from '../services/myServices';
  
      export const getProduct = (req, res, next) =&gt; {
        try {
          const { type } = req.params;
  
          const { id, productCode } = req.body;
  
          if (!id || !productCode) {
            res.status(400).json({ error: { message: 'Id or productCode is required' } });
          } else {
            switch (type.toUpperCase()) {
              case 'X':
                try {
                  const result = calcu(id, productCode);
                  res.status(200).json(result);
                } catch (err) {
                  res.status(400).json({ error: { message: err.message } });
                }
                break;
              default:
                res.status(400).json({ error: { message: `type ${type} is not support` } });
            }
          }
        } catch (err) {
          next(err);
        }
      };
  </code></pre>
  
  <p>This my unit test code in this case:</p>
  
  <pre><code>    import { getProduct } from './quotationController';
  
      describe('Controller', () =&gt; {
          let json, res, status;
          test('Should return message error if the id or productCode is missing', () =&gt; {
              const req = {
                  body: { id: "1111" },
                  param: { type: "qqqqq" }
              };
              const next = err =&gt; err.message;
              const result = getProduct(req, res, next);
              //expect(result).toBe(undefined);
              expect(result).toEqual({
                  code: 400,
                  message: 'Id or productCode is required'
              });
          });
      })
  </code></pre>
  
  <p>I got an error when I ran the unit test code: </p>
  
  <blockquote>
    <p>result is undefined.</p>
  </blockquote>