Files
Shuaib Hasan Akib efaf431b6d docs(docs-infra): modernize remaining shared-docs tests
Follow-up to 3a85031dc0. Replace the last `fixture.detectChanges()` calls in
the shared-docs specs with `await fixture.whenStable()`, matching the
zoneless "act, wait, assert" pattern used by the rest of adev's tests.
2026-10-02 14:20:30 -04:00

45 lines
1.4 KiB
TypeScript

/*!
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {SlideToggle} from './slide-toggle.component';
describe('SlideToggle', () => {
let component: SlideToggle;
let fixture: ComponentFixture<SlideToggle>;
beforeEach(async () => {
fixture = TestBed.createComponent(SlideToggle);
fixture.componentRef.setInput('buttonId', 'id');
fixture.componentRef.setInput('label', 'foo');
component = fixture.componentInstance;
await fixture.whenStable();
});
it('should toggle the value when clicked', () => {
expect(component['checked']()).toBeFalse();
const buttonElement = fixture.nativeElement.querySelector('input');
buttonElement.click();
expect(component['checked']()).toBeTrue();
});
it('should set active class for button when is checked', async () => {
component.checked.set(true);
await fixture.whenStable();
const buttonElement: HTMLButtonElement = fixture.nativeElement.querySelector('input');
expect(buttonElement.classList.contains('docs-toggle-active')).toBeTrue();
component.checked.set(false);
await fixture.whenStable();
expect(buttonElement.classList.contains('docs-toggle-active')).toBeFalse();
});
});