Skip to content

Commit 6f6255d

Browse files
author
Yakov Tchenak
committed
fix: support signal model output
1 parent 0fc3e91 commit 6f6255d

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

libs/ng-mocks/src/lib/common/func.directive-io-parse.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ export default function (param: DirectiveIo): DirectiveIoParsed {
88
return { name };
99
}
1010

11+
if (name + 'Change' === alias) {
12+
return { name: alias }; // model output
13+
}
14+
1115
return { name, alias };
1216
}
1317

tests/issue-10942/test.spec.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import {
2+
Component,
3+
model,
4+
NO_ERRORS_SCHEMA,
5+
signal,
6+
} from '@angular/core';
7+
import { TestBed } from '@angular/core/testing';
8+
9+
import { MockBuilder, ngMocks } from 'ng-mocks';
10+
11+
@Component({
12+
selector: 'app-signal',
13+
['standalone' as never /* TODO: remove after upgrade to a14 */]:
14+
true,
15+
template: ``,
16+
})
17+
export class SignalComponent {
18+
model = model('');
19+
}
20+
@Component({
21+
imports: [SignalComponent],
22+
['standalone' as never /* TODO: remove after upgrade to a14 */]:
23+
true,
24+
schemas: [NO_ERRORS_SCHEMA], // TODO: remove after upgrade to a16
25+
template: `
26+
<h1>{{ title() }}</h1>
27+
<app-signal [(model)]="title"></app-signal>
28+
`,
29+
})
30+
export class TargetComponent {
31+
title = signal('test-default');
32+
}
33+
34+
describe('issue-10942', () => {
35+
beforeEach(() => MockBuilder(TargetComponent));
36+
37+
it('issue-10942', () => {
38+
const fixture = TestBed.createComponent(TargetComponent);
39+
fixture.detectChanges();
40+
ngMocks.output('app-signal', 'modelChange').emit('test-new');
41+
fixture.detectChanges();
42+
expect(ngMocks.find('h1').nativeElement.innerHTML).toEqual(
43+
'test-new',
44+
);
45+
});
46+
});

0 commit comments

Comments
 (0)