Repository: angular
Issue: NullInjectorError: R3InjectorError(DynamicTestModule) When Testing with Standalone Component from Library
Labels: area: testing

### Which @angular/* package(s) are the source of the bug?

core

### Is this a regression?

No

### Description

This took a while to narrow down to something I could isolate / re-create.  If I create a standalone component that uses `MatTooltipModule` in a library, and then use that library/component from within a component in an Angular app that doesn't also import `MatTooltipModule`, I get the following `NullInjectorError` when I run unit tests:

```bash
NullInjectorError: R3InjectorError(DynamicTestModule)[InjectionToken mat-tooltip-scroll-strategy -> InjectionToken mat-tooltip-scroll-strategy]:
      NullInjectorError: No provider for InjectionToken mat-tooltip-scroll-strategy!
```

`mat-tooltip-scroll-strategy` is an injection token provided by `MatTooltipModule`.  Now, if I build the same component locally in the app, and then use that component in another component, I don't face the issue at all.  It only seems to be when using it from a library.  This also doesn't throw an error at runtime.  It only seems to present itself when testing.  It also works, if I import `MatTooltipModule` again from the component that's using the library-based component.  But I wouldn't expect it to need that, since both are standalone and the component that's using the tooltip imports it.   Not sure if this is relevant, but we use `jest` for testing (with the `jest-preset-angular` library for our config).  

I managed to recreate this in the attached repo, which demonstrates that the locally built component set up works, while the library-built version of the same component doesn't work.

### Please provide a link to a minimal reproduction of the bug

https://github.com/michaelfaith/angular-nullinjector-bug

### Please provide the exception or error you saw

```true
NullInjectorError: R3InjectorError(DynamicTestModule)[InjectionToken mat-tooltip-scroll-strategy -> InjectionToken mat-tooltip-scroll-strategy]:
      NullInjectorError: No provider for InjectionToken mat-tooltip-scroll-strategy!
```


### Please provide the environment you discovered this bug in (run `ng version`)

```true
Angular CLI: 16.1.4
Node: 16.19.0
Package Manager: yarn 1.22.19
OS: win32 x64

Angular: 16.1.5
... animations, cdk, common, compiler, compiler-cli, core, forms
... language-service, material, platform-browser
... platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1601.4
@angular-devkit/build-angular   16.1.4
@angular-devkit/core            16.1.4
@angular-devkit/schematics      16.1.4
@angular/cli                    16.1.4
@schematics/angular             16.1.4
ng-packagr                      16.1.0
rxjs                            7.8.1
typescript                      5.0.4
```


### Anything else?

I found these issues, which involved similar errors, but didn't have the exact same situation as ours (where's it's working when built locally, but not when built in a library).

https://github.com/angular/angular/issues/35759
https://github.com/angular/angular/issues/47448
https://github.com/angular/angular/issues/50312