Skip to content

Commit d4c10d1

Browse files
AndrewKushnirdylhunn
authored andcommitted
test(core): replace hand-written instructions in ComponentRef tests with TestBed (angular#46528)
This commit updates a set of ComponentRef tests to avoid using hand-written instructions and replace them with TestBed APIs. PR Close angular#46528
1 parent a3f7046 commit d4c10d1

File tree

1 file changed

+31
-38
lines changed

1 file changed

+31
-38
lines changed

packages/core/test/render3/component_ref_spec.ts

+31-38
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
*/
88

99
import {RElement} from '@angular/core/src/render3/interfaces/renderer_dom';
10-
import {Injector, NgModuleRef, RendererType2, ViewEncapsulation} from '../../src/core';
10+
11+
import {Component, Injector, Input, NgModuleRef, Output, RendererType2, ViewEncapsulation} from '../../src/core';
1112
import {ComponentFactory} from '../../src/linker/component_factory';
1213
import {RendererFactory2} from '../../src/render/api';
1314
import {injectComponentFactoryResolver} from '../../src/render3/component_ref';
14-
import {AttributeMarker, ɵɵdefineComponent} from '../../src/render3/index';
1515
import {domRendererFactory3, Renderer3, RendererFactory3} from '../../src/render3/interfaces/renderer';
1616
import {Sanitizer} from '../../src/sanitization/sanitizer';
1717

@@ -20,15 +20,12 @@ describe('ComponentFactory', () => {
2020

2121
describe('constructor()', () => {
2222
it('should correctly populate default properties', () => {
23+
@Component({
24+
selector: 'test[foo], bar',
25+
standalone: true,
26+
template: '',
27+
})
2328
class TestComponent {
24-
static ɵfac = () => new TestComponent();
25-
static ɵcmp = ɵɵdefineComponent({
26-
type: TestComponent,
27-
selectors: [['test', 'foo', ''], ['bar']],
28-
decls: 0,
29-
vars: 0,
30-
template: () => undefined,
31-
});
3229
}
3330

3431
const cf = cfr.resolveComponentFactory(TestComponent);
@@ -41,25 +38,23 @@ describe('ComponentFactory', () => {
4138
});
4239

4340
it('should correctly populate defined properties', () => {
41+
@Component({
42+
selector: 'test[foo], bar',
43+
standalone: true,
44+
template: `
45+
<ng-content></ng-content>
46+
<ng-content select="a"></ng-content>
47+
<ng-content select="b"></ng-content>
48+
`,
49+
})
4450
class TestComponent {
45-
static ɵfac = () => new TestComponent();
46-
static ɵcmp = ɵɵdefineComponent({
47-
type: TestComponent,
48-
encapsulation: ViewEncapsulation.None,
49-
selectors: [['test', 'foo', ''], ['bar']],
50-
decls: 0,
51-
vars: 0,
52-
template: () => undefined,
53-
ngContentSelectors: ['*', 'a', 'b'],
54-
inputs: {
55-
in1: 'in1',
56-
in2: ['input-attr-2', 'in2'],
57-
},
58-
outputs: {
59-
out1: 'out1',
60-
out2: 'output-attr-2',
61-
},
62-
});
51+
@Input() in1: unknown;
52+
53+
@Input('input-attr-2') in2: unknown;
54+
55+
@Output() out1: unknown;
56+
57+
@Output('output-attr-2') out2: unknown;
6358
}
6459

6560
const cf = cfr.resolveComponentFactory(TestComponent);
@@ -89,17 +84,15 @@ describe('ComponentFactory', () => {
8984
jasmine.createSpy('RendererFactory2#createRenderer').and.returnValue(document),
9085
createRenderer3Spy = spyOn(domRendererFactory3, 'createRenderer').and.callThrough();
9186

87+
@Component({
88+
selector: 'test',
89+
template: '...',
90+
host: {
91+
'class': 'HOST_COMPONENT',
92+
},
93+
encapsulation: ViewEncapsulation.None
94+
})
9295
class TestComponent {
93-
static ɵfac = () => new TestComponent();
94-
static ɵcmp = ɵɵdefineComponent({
95-
type: TestComponent,
96-
encapsulation: ViewEncapsulation.None,
97-
selectors: [['test']],
98-
decls: 0,
99-
vars: 0,
100-
template: () => undefined,
101-
hostAttrs: [AttributeMarker.Classes, 'HOST_COMPONENT']
102-
});
10396
}
10497

10598
cf = cfr.resolveComponentFactory(TestComponent);

0 commit comments

Comments
 (0)