Skip to content
This repository was archived by the owner on Jul 15, 2026. It is now read-only.
This repository was archived by the owner on Jul 15, 2026. It is now read-only.

Not indicative error message when passing undefined instead of app #11

Description

@NivGreenstein

Describe the bug
I was dumb and passed uninitialized app: Express.Application variable.
I got the following error:

    TypeError: Cannot read properties of undefined (reading 'address')

      137 |         ],
      138 |       };
    > 139 |       const response = await requestSender.merger({
          |                                            ^
      140 |         requestBody: body,
      141 |       });
      142 |

      at Test.serverAddress (node_modules/supertest/lib/test.js:46:22)
      at new Test (node_modules/supertest/lib/test.js:34:14)
      at TestAgent.<computed> [as post] (node_modules/supertest/lib/agent.js:64:17)
      at sendRequest (node_modules/@map-colonies/openapi-helpers/src/requestSender/requestSender.ts:27:45)
      at Object.returnObj.<computed> [as merger] (node_modules/@map-colonies/openapi-helpers/src/requestSender/requestSender.ts:122:7)
      at Object.merger (tests/integration/merger/merge.spec.ts:139:44)

To Reproduce
Steps to reproduce the behavior:

  1. Create test like the following
  2. pass undefined instead of app
  3. See error

Expected behavior
I would like to get an error that app property was passed as undefined instead of current message.

Additional context

Example code:

describe('merge', function () {
  let app: Application;
  let configInstance: ConfigType;
  let requestSender: RequestSender<paths, operations>;

  beforeAll(async function () {
    await initConfig(true);
    configInstance = getConfig();

    const [initializeApp] = await getApp({
      override: [
        {
          token: SERVICES.CONFIG,
          provider: { useValue: configInstance },
        },
        { token: SERVICES.LOGGER, provider: { useValue: jsLogger({ enabled: false }) } },
        {
          token: SERVICES.TRACER,
          provider: {
            useValue: trace.getTracer('test-tracer'),
          },
        },
      ],
      useChild: true,
    });

    requestSender = await createRequestSender<paths, operations>('openapi3.yaml', app);

    app = initializeApp;
  });

  describe('Happy Path', function () {
    it('should return 200 status code and the resource', async function () {
      const body = ....

      const response = await requestSender.merger({
        requestBody: body,
      });

      expect(response).toHaveProperty('status', httpStatusCodes.OK);
      expect(response).toHaveProperty('body', expected);
    });
  });
 });

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions