Given a service with a dependency injected though a token and a test for the service, the test fails with a ReferenceError for the injection token depending on the import statement in the service.
For example a service...
@Injectable({ providedIn: 'root' })
export class ExampleService {
public constructor(
@Inject(EXAMPLE_TOKEN) private readonly _dependency: ExampleDependency
) {}
public foo(): number {
return this._dependency.foo();
}
}
Describe the Bug
Given a service with a dependency injected though a token and a test for the service, the test fails with a
ReferenceError
for the injection token depending on the import statement in the service.For example a service...
...with a dependency...
...and a test:
Depending on the import statement for the dependency in the service, the test fails with a
ReferenceError: example_dependency_2 is not defined
.The following import causes the error:
But combining them into a single import (even with type) works as expected:
Minimal Reproduction
https://github.com/raphaelmeyer/angular-builder-jest-import-error
Expected Behavior
I would expect the same behavior from both import statement variants.
Environment
@angular-builders/jest@17.0.3
jest@29.7.0
Additional Context
I just did a quick test with
@angular-devkit/build-angular:jest
instead of@angular-builders/jest:run
. Then the error does not occur.