Skip to content

unclear documentation about test setup with circular dependency of repositories #2568

@derdeka

Description

@derdeka

Description / Steps to reproduce / Feature proposal

According to https://loopback.io/doc/en/lb4/Testing-your-application.html the database.helpers.ts should look something like this:

export async function givenEmptyDatabase() {
  const categoryRepository = new CategoryRepository(testdb);
  const productRepository = new ProductRepository(
    testdb,
    Getter.fromValue(categoryRepository),
  );

  await productRepository.deleteAll();
  await categoryRepository.deleteAll();
}

But because of belongsTo and hasMany relation for me it has to be something like this (circular dependency):

export async function givenEmptyDatabase() {
  const categoryRepository = new CategoryRepository(
    testdb,
    Getter.fromValue(productRepository),
  );
  const productRepository = new ProductRepository(
    testdb,
    Getter.fromValue(categoryRepository),
  );

  ...
}

Is it really necessary to setup all repositories like this for the tests as the ioc container is doing the same thing automatically? My guess is, that the test database should be bound to the test application and that's it.

Current Behavior

Unclear documentation about test setup with circular dependency of repositories.

Expected Behavior

Improved example - what to do with circular dependencies?

Acceptance Criteria

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions