Skip to content

Commit 1898eee

Browse files
author
Alex Malkevich
committed
feat(host): allow to override generated template
1 parent 52aa96d commit 1898eee

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

projects/ngx-testing/src/lib/host-generator.service.ts

+15-9
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,13 @@ export class HostGeneratorService {
7979
genForComponent<T>(compType: Type<T>): Type<AsHostComponent<T>> {
8080
const factory = this.cfr.resolveComponentFactory(compType);
8181
const selector = `host-${factory.selector}`;
82-
const template = genHostCompTpl(
83-
factory.selector,
84-
factory,
85-
this.extraConfig.projectContent,
86-
);
82+
const template =
83+
this.extraConfig.template ||
84+
genHostCompTpl(
85+
factory.selector,
86+
factory,
87+
this.extraConfig.projectContent,
88+
);
8789

8890
return this.genComponent({ selector, template }, compType, factory);
8991
}
@@ -92,14 +94,18 @@ export class HostGeneratorService {
9294
const io = getDirectiveIO(dirType);
9395

9496
const selector = `host-directive`;
95-
const templateTag = this.extraConfig.hostComponent
97+
98+
const templateTag = this.extraConfig.template
99+
? ''
100+
: this.extraConfig.hostComponent
96101
? this.cfr.resolveComponentFactory(this.extraConfig.hostComponent)
97102
.selector
98103
: this.extraConfig.hostTag;
99104

100-
const template = templateTag
101-
? this.genDirectiveTemplate(templateTag, io)
102-
: '';
105+
const template =
106+
this.extraConfig.template || templateTag
107+
? this.genDirectiveTemplate(templateTag, io)
108+
: '';
103109

104110
return this.genComponent({ selector, template }, dirType, io);
105111
}

projects/ngx-testing/src/lib/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
import { OutputMock } from './output-mock';
1010

1111
export interface TestingModuleExtras {
12+
template?: string;
1213
projectContent?: string;
1314
}
1415

0 commit comments

Comments
 (0)