-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Description
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
- Find the correct way to write the integration tests for repositories with circular dependencies.
- Either figure out a working solution or fix the existing code.
- Update the documentation on https://loopback.io/doc/en/lb4/Testing-your-application.html with the new approach accordingly.