NG 21 + Vitest + Неавтономный компонент с асинхронным каналомHtml

Программисты Html
Ответить
Anonymous
 NG 21 + Vitest + Неавтономный компонент с асинхронным каналом

Сообщение Anonymous »

В Angular 21 я не могу тестировать (с помощью vitest) автономный компонент с помощью канала Async. Я получаю следующую ошибку:

Код: Выделить всё

X [ERROR] NG8004: No pipe found with name 'async'.
To fix this, import the "AsyncPipe" class from "@angular/common" and add it to the "imports" array of the module declaring the component. [plugin angular-compiler]

src/app/async-test/async-test.html:1:9:
1 │ {{v | async }}
╵          ~~~~~

Error occurs in the template of component AsyncTestComponent.

src/app/async-test/async-test.ts:6:15:
6 │   templateUrl: './async-test.html',
╵                ~~~~~~~~~~~~~~~~~~~
Вот полный код:
Тест:

Код: Выделить всё

describe('AsyncTestComponent', () => {
let component: AsyncTestComponent;
let fixture: ComponentFixture;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [CommonModule, AsyncPipe ],
declarations: [AsyncTestComponent]
})
.compileComponents();

fixture = TestBed.createComponent(AsyncTestComponent);
component = fixture.componentInstance;
await fixture.whenStable();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Компонент:

Код: Выделить всё

@Component({
selector: 'app-async-test',
templateUrl: './async-test.html',
styleUrl: './async-test.css',
standalone: false
})
export class AsyncTestComponent {
protected readonly v = of(1);
}
HTML:

Код: Выделить всё

{{v | async }}
Все, что я сделал, это: --> добавьте неавтономный компонент и используйте в нем асинхронный канал, а затем запустите ng test
Сталкивался ли кто-нибудь еще с такой же проблемой?

Подробнее здесь: https://stackoverflow.com/questions/798 ... async-pipe
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Html»