Skip to content

The connection remains open #22

@Edo78

Description

@Edo78

If I add even another simple test like

  it('should be defined', () => {
    expect(service).toBeDefined();
  });

to src/spaceships/spaceships.service.spec.ts then I start to get an error

[Nest] 559866  - 20/11/2021, 23:13:03   ERROR [TypeOrmModule] Unable to connect to the database. Retrying (1)...
AlreadyHasActiveConnectionError: Cannot create a new connection named "default", because connection with such name already exist and it now has an active connection session.
    at AlreadyHasActiveConnectionError.TypeORMError [as constructor] (/tmp/unit-testing-nestjs-using-typeorm-in-memory/src/error/TypeORMError.ts:7:9)
    at new AlreadyHasActiveConnectionError (/tmp/unit-testing-nestjs-using-typeorm-in-memory/src/error/AlreadyHasActiveConnectionError.ts:8:9)
    at ConnectionManager.Object.<anonymous>.ConnectionManager.create (/tmp/unit-testing-nestjs-using-typeorm-in-memory/src/connection/ConnectionManager.ts:57:23)
    at /tmp/unit-testing-nestjs-using-typeorm-in-memory/src/globals.ts:77:35
    at step (/tmp/unit-testing-nestjs-using-typeorm-in-memory/node_modules/tslib/tslib.js:143:27)
    at Object.next (/tmp/unit-testing-nestjs-using-typeorm-in-memory/node_modules/tslib/tslib.js:124:57)
    at /tmp/unit-testing-nestjs-using-typeorm-in-memory/node_modules/tslib/tslib.js:117:75
    at new Promise (<anonymous>)
    at Object.__awaiter (/tmp/unit-testing-nestjs-using-typeorm-in-memory/node_modules/tslib/tslib.js:113:16)
    at createConnection (/tmp/unit-testing-nestjs-using-typeorm-in-memory/node_modules/typeorm/globals.js:55:20)

until the test goes in timeout.

You should add an afterEach to close the module.

Let me know if you'd like that I write a PR

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions