Skip to content

Commit

Permalink
fix(MockBuilder): touches kept modules in standalone components help-…
Browse files Browse the repository at this point in the history
  • Loading branch information
satanTime committed Apr 23, 2023
1 parent a9c0f32 commit 1589172
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
3 changes: 2 additions & 1 deletion libs/ng-mocks/src/lib/mock-builder/promise/init-universe.ts
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();
});
});

0 comments on commit 1589172

Please sign in to comment.