Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Angular Signal model not getting called when updated via ngModel #30417

Open
ischemicbg opened this issue Oct 17, 2024 · 0 comments
Open

Angular Signal model not getting called when updated via ngModel #30417

ischemicbg opened this issue Oct 17, 2024 · 0 comments
Labels
CT Issue related to component testing npm: @cypress/angular @cypress/angular package issues stage: needs investigating Someone from Cypress needs to look at this

Comments

@ischemicbg
Copy link

ischemicbg commented Oct 17, 2024

Current behavior

On one of my components I have a signal model() which is bound to an html input via [(ngModel)] like so:

searchTerm = model('');
<input
		name="search"
		type="search"
		[placeholder]="placeholder()"
		autocomplete="off"
		#searchField
		[(ngModel)]="searchTerm"
		[disabled]="disabled()"
			/>

I'm trying to test that the searchTermOutput fires when the value in the input changes. My test code is as follows:

    cy.mount(SearchComponent, {
	componentProperties: {
		// @ts-expect-error
		searchTermChange: createOutputSpy('searchTermChange'),
	},
        cy.get('input').type('son');
        cy.get('@searchTermChange').should('have.been.called');
    });

The test fails saying searchTermChange was never called:

image

Desired behavior

Cypress should detect output changes when trigged via ngModel binding

Test code to reproduce

Basic example to reproduce

import { Component, model } from '@angular/core';
import { FormsModule } from '@angular/forms';

@Component({
	selector: 'app-test',
	standalone: true,
	template: '<input name="search" type="search" autocomplete="off" [(ngModel)]="searchTerm" />',
	imports: [FormsModule],
})
export class TestComponent {
	public searchTerm = model('');
}
import { TestComponent } from './test.component.ts';
import { createOutputSpy } from 'cypress/angular-signals';
describe('TestComponent', () => {
	it('model() searchTerm - When text is typed into search input his output will fire with that term', () => {
		cy.mount(TestComponent, {
			componentProperties: {
				// @ts-expect-error
				searchTermChange: createOutputSpy('searchTermChange'),
			},
		});

		cy.get('input').type('son');
		cy.get('@searchTermChange').should('have.been.called');
	});
});

Cypress Version

13.15.0

Node version

v18.20

Operating System

Windows 11

Debug Logs

No response

Other

No response

@jennifer-shehane jennifer-shehane added stage: needs investigating Someone from Cypress needs to look at this npm: @cypress/angular @cypress/angular package issues CT Issue related to component testing labels Oct 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CT Issue related to component testing npm: @cypress/angular @cypress/angular package issues stage: needs investigating Someone from Cypress needs to look at this
Projects
None yet
Development

No branches or pull requests

2 participants