Skip to content

Angular CT providers are not added to the TestingModule #23427

@NicBright

Description

@NicBright

Current behavior

The bug is obvious:

const { providers, ...configRest } = config
const componentFixture = createComponentFixture(component) as Type<T>
TestBed.configureTestingModule({
...bootstrapModule(componentFixture, configRest),
})
if (providers != null) {
TestBed.overrideComponent(componentFixture, {
add: {
providers,
},
})
}

The providers that are meant to be added to the TestingModule are instead only added in a call to TestBed.overrideComponent(). This way, it is not possible to alter dependencies of singleton services aka services that are { providedIn: 'root' } (or any custom module).

Desired behavior

Passed providers must be passed to TestBed.configureTestingModule()

Test code to reproduce

Irrelevant. See source code snippet above.

Cypress Version

10.6.0

Node version

irrelevant

Operating System

irrelevant

Debug Logs

No response

Other

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    CTIssue related to component testing

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions