Description
I discovered a bug related to the usage of the @Inject decorator with forwardRef in the class constructor (with NestJS). When circular dependencies exist due to the import statements, the reflection mechanism of reflect-metadata doesn't work correctly, resulting in undefined values for the forward-referenced dependency (dependency in this case).
The scenario is as follows:
class Main {
public constructor(
@Inject(forwardRef(() => Dependency)) private readonly dependency: Dependency;
) {}
}
When the reflect-metadata is unable to resolve the circular import, the dependencySix property ends up being assigned the value undefined, rather than properly reflecting the intended type DependencySix.
This issue disrupts Automock's ability to handle classes with circular dependencies that involve the use of forwardRef, leading to unexpected behavior and possible errors when trying to mock and test such classes.
Steps to Reproduce:
- Set up a class constructor with a dependency using
@Inject and forwardRef, as shown in the description.
- Trigger the circular import scenario to create the reflection issue.
- Attempt to use Automock to mock the dependencies and perform unit tests on the class.
Expected Behavior:
Automock should correctly reflect the forwardRef dependency and provide the expected type DependencySix for the dependencySix property.
Current Behavior:
Due to the circular import causing a reflection issue, Automock assigns the dependencySix property the value undefined, resulting in incorrect behavior during mocking and testing.
Possible Solution:
To resolve this issue, modifications need to be made to the Automock logic. Specifically, handling the circular import scenario properly and ensuring that the forwardRef dependency is correctly reflected to avoid assigning undefined to the property.
Might be related to #67
Description
I discovered a bug related to the usage of the
@Injectdecorator withforwardRefin the class constructor (with NestJS). When circular dependencies exist due to theimportstatements, the reflection mechanism ofreflect-metadatadoesn't work correctly, resulting inundefinedvalues for the forward-referenced dependency (dependencyin this case).The scenario is as follows:
When the
reflect-metadatais unable to resolve the circular import, thedependencySixproperty ends up being assigned the valueundefined, rather than properly reflecting the intended typeDependencySix.This issue disrupts Automock's ability to handle classes with circular dependencies that involve the use of
forwardRef, leading to unexpected behavior and possible errors when trying to mock and test such classes.Steps to Reproduce:
@InjectandforwardRef, as shown in the description.Expected Behavior:
Automock should correctly reflect the
forwardRefdependency and provide the expected typeDependencySixfor thedependencySixproperty.Current Behavior:
Due to the circular import causing a reflection issue, Automock assigns the
dependencySixproperty the valueundefined, resulting in incorrect behavior during mocking and testing.Possible Solution:
To resolve this issue, modifications need to be made to the Automock logic. Specifically, handling the circular import scenario properly and ensuring that the
forwardRefdependency is correctly reflected to avoid assigningundefinedto the property.Might be related to #67