/
githubmirror
/
angular
Обзор
Документация
Войти
/
githubmirror
/
angular
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
integration/cli-signal-inputs/src/app/greet.component.spec.ts
47 строк
1 KB
Matthieu Riegler
feat(core): Set default Component changeDetection strategy to OnPush
25 мар 2026, 02:25
25 мар 2026, 02:25
eae8f7e
Код
Авторство
О чём код?
import {ChangeDetectionStrategy, Component} from '@angular/core'; import {TestBed} from '@angular/core/testing'; import {GreetComponent} from './greet.component'; describe('greet component', () => { it('should allow binding to an input', () => { const fixture = TestBed.createComponent(TestCmp); fixture.detectChanges(); expect(fixture.nativeElement.textContent).toBe('Initial - initial-unset'); fixture.componentInstance.firstName = 'John'; fixture.changeDetectorRef.markForCheck(); fixture.detectChanges(); expect(fixture.nativeElement.textContent).toBe('John - initial-unset'); }); it('should emit an event for the click output', () => { const fixture = TestBed.createComponent(TestCmp); fixture.detectChanges(); fixture.nativeElement.querySelector('button').dispatchEvent(new MouseEvent('click')); fixture.detectChanges(); expect(fixture.componentInstance.clickCount).toBe(1); expect(fixture.componentInstance.clickCount2).toBe(1); }); }); @Component({ template: ` <greet [firstName]="firstName" (clickFromInside)="clickCount = clickCount + 1" (clickFromInside2)="clickCount2 = clickCount2 + 1" /> `, imports: [GreetComponent], changeDetection: ChangeDetectionStrategy.Eager, }) class TestCmp { clickCount = 0; clickCount2 = 0; firstName = 'Initial'; }