Skip to content

Bug: The mock for bidirectional binding to a signal model is missing the model output event emitter #10942

@ytchenak

Description

@ytchenak

Description of the bug

The mock for bidirectional binding to a signal model is missing the model output event emitter.
The ngMocks.output function cannot access the model's output using the model name with the 'Change' suffix.

An example of the bug

TypeError: ng_mocks_1.ngMocks.output(...).emit is not a function  

Important: The issue only appears if change detection occurs after the component is created. Otherwise, the bug does not manifest.

import { Component, model, signal } from '@angular/core';
import { TestBed } from '@angular/core/testing';
import { MockBuilder, ngMocks } from 'ng-mocks';

@Component({
  selector: 'app-signal',
  imports: [],
  template: ``,
})
export class SignalComponent {
  model = model('')
}
@Component({
  imports: [ SignalComponent],
  selector: 'app-target',
  template: `
    <h1>{{title()}}</h1>
    <app-signal [(model)]=title></app-signal>
  `,
})
export class TargetComponent {
  title = signal('test-default');
}

describe('issue-signal-model', () => {
  beforeEach( () => MockBuilder(TargetComponent) );

  it('issue-signal-model', () => {
    const fixture = TestBed.createComponent(TargetComponent);
    fixture.detectChanges();
    ngMocks.output('app-signal', 'modelChange').emit('test-new');
    fixture.detectChanges();
    expect(ngMocks.find('h1').nativeElement.innerHTML).toEqual('test-new');
  });

});

Expected vs actual behavior

  • Expected: The ngMocks.output function should always be able to access the signal model's output using the model name with the 'Change' suffix.
  • Actual: The function cannot find or emit the expected output event, leading to a TypeError.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingtodo

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions