/
githubmirror
/
angular
Обзор
Документация
Войти
/
githubmirror
/
angular
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
adev/src/app/features/references/api-items-section/api-items-section.component.spec.ts
79 строк
2 KB
Matthieu Riegler
docs(docs-infra): Modernize tests
05 янв 2026, 19:47
05 янв 2026, 19:47
3a85031
Код
Авторство
О чём код?
/*! * @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 ApiItemsSection from './api-items-section.component'; import {ApiItemsGroup} from '../interfaces/api-items-group'; import {ApiItemType} from '../interfaces/api-item-type'; import {provideRouter} from '@angular/router'; import {By} from '@angular/platform-browser'; describe('ApiItemsSection', () => { let component: ApiItemsSection; let fixture: ComponentFixture<ApiItemsSection>; const fakeGroup: ApiItemsGroup = { title: 'Group', id: 'group', items: [ { title: 'Fake Deprecated Title', itemType: ApiItemType.CONST, url: 'api/fakeDeprecatedTitle', deprecated: {version: undefined}, developerPreview: undefined, experimental: undefined, stable: undefined, category: undefined, }, { title: 'Fake Standard Title', itemType: ApiItemType.DIRECTIVE, url: 'api/fakeTitle', deprecated: undefined, developerPreview: undefined, experimental: undefined, stable: undefined, category: undefined, }, ], }; beforeEach(() => { TestBed.configureTestingModule({ imports: [ApiItemsSection], providers: [provideRouter([])], }); fixture = TestBed.createComponent(ApiItemsSection); component = fixture.componentInstance; }); it('should render list of all APIs of provided group', async () => { fixture.componentRef.setInput('group', fakeGroup); await fixture.whenStable(); const apis = fixture.debugElement.queryAll(By.css('.adev-api-items-section-grid li')); expect(apis.length).toBe(2); }); it('should display deprecated icon for deprecated API', async () => { fixture.componentRef.setInput('group', fakeGroup); await fixture.whenStable(); const deprecatedApiIcons = fixture.debugElement.queryAll( By.css('.adev-api-items-section-grid li .adev-item-attribute'), ); const deprecatedApiTitle = deprecatedApiIcons[0].parent?.query(By.css('.adev-item-title')); expect(deprecatedApiIcons.length).toBe(1); expect(deprecatedApiIcons[0]).toBeTruthy(); expect(deprecatedApiTitle?.nativeElement.innerText).toBe('Fake Deprecated Title'); }); });