Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(MockBuilder): touches kept modules in standalone components #5520 #5529

Merged
merged 1 commit into from
Apr 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export default ({

const dependencies = initKeepDef(keepDef, configDef);
for (const dependency of mapValues(dependencies)) {
ngMocksUniverse.touches.add(dependency);

// MockBuilder has instruction about the dependency, skipping it.
if (configDef.has(dependency)) {
continue;
Expand All @@ -52,7 +54,6 @@ export default ({
dependency: true,
__internal: true,
});
ngMocksUniverse.touches.add(dependency);
}

for (const [k, v] of mapEntries(configDef)) {
Expand Down
53 changes: 53 additions & 0 deletions tests/issue-5520/test.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { Component, NgModule, VERSION } from '@angular/core';

import { MockBuilder, MockRender } from 'ng-mocks';

// @see https://github.com/help-me-mom/ng-mocks/issues/5520
describe('issue-5520', () => {
if (Number.parseInt(VERSION.major, 10) < 15) {
it('needs a15', () => {
// pending('Need Angular 15+');
expect(true).toBeTruthy();
});

return;
}

@Component({
selector: 'dependency',
template: '',
})
class DependencyComponent {
dependency5520() {}
}

@NgModule({
declarations: [DependencyComponent],
exports: [DependencyComponent],
})
class DependencyModule {}

@Component(
{
selector: 'standalone',
standalone: true,
template: '<dependency></dependency>',
imports: [DependencyModule],
} as never /* TODO: remove after upgrade to a15 */,
)
class StandaloneComponent {
standalone5520() {}
}

beforeEach(() =>
MockBuilder(StandaloneComponent, null)
.keep(DependencyModule)
.mock(DependencyComponent),
);
// Error: MockBuilder has found a missing dependency: DependencyModule. It means no module provides it.
// Please, use the "export" flag if you want to add it explicitly. https://ng-mocks.sudo.eu/api/MockBuilder#export-flag

it('creates StandaloneComponent', () => {
expect(() => MockRender(StandaloneComponent)).not.toThrow();
});
});