我的应用程序运行得很好.我的应用程序是独立的组件应用程序.当我try 测试组件时,我得到了Karma中标题中提到的错误.

导入我的组件

import { Component } from '@angular/core';
import {MatSelectModule} from '@angular/material/select';
import {MatFormFieldModule} from '@angular/material/form-field';
import { NavigationComponent } from '../../../0_navigation/navigation.component';
import jsonDataShipments from '../../../../../assets/shipments.json';

@Component({
  selector: 'app-sort-functionality',
  standalone: true,
  imports: [NavigationComponent, MatFormFieldModule, MatSelectModule],
  templateUrl: './sort-functionality.component.html',
  styleUrl: './sort-functionality.component.css'
})

我的应用程序的配置

import { ApplicationConfig } from '@angular/core';
import { provideRouter } from '@angular/router';

import { routes } from './app.routes';
import { provideHttpClient } from '@angular/common/http';
import { provideAnimationsAsync } from '@angular/platform-browser/animations/async';

export const appConfig: ApplicationConfig = {
  providers: [
    provideRouter(routes),
    provideHttpClient(), provideAnimationsAsync(),
  ],
};

误差率

误差率: NG05105: Unexpected synthetic property @transitionMessages found. Please make sure that:
  - Either `BrowserAnimationsModule` or `NoopAnimationsModule` are imported in your application.
  - There is corresponding configuration for the animation named `@transitionMessages` defined in the `animations` field of the `@Component` decorator (see https://angular.io/api/core/Component#animations).

如果我导入BrowserAnimationsModule

我得到了这个错误

Uncaught (in promise): 误差率: Providers from the `BrowserModule` have already been loaded. If you need access to common directives such as NgIf and NgFor, import the `CommonModule` instead.
误差率: Providers from the `BrowserModule` have already been loaded. If you need access to common directives such as NgIf and NgFor, import the `CommonModule` instead.

推荐答案

您应该try 导入BrowserAnimationsModule,如下所示:

import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

并将其导入到您的测试文件中,如下所示:

imports: [YourComponentName, BrowserAnimationsModule]

希望这个能帮上忙!

Angular相关问答推荐

我使用最新的AuthGuard方法,应该使用路由重定向.UrlTree如果用户未登录但未能登录

如何在Angular模块中的forRoot中注入配置

Angular 16路卫单元测试可观察到的SpyObj属性

接收错误NullInjectorError:R3InjectorError(_AppModule)[config—config]....>过度安装Angular—Markdown—Editor

命令不起作用的初始菜单项

独立Angular 零部件不在辅零部件或共享零部件中工作

Angular 16独立依赖注入问题

获取 Angular 中所有子集合 firestore 的列表

Angular 为什么延迟加载返回空路径?

Angular 15 Ref 错误:初始化前无法访问组件 A

Angular 在关闭另一个对话框后打开另一个对话框的最佳做法是什么?

应该显示在表格中的嵌套循环

Angular:为什么在 ngAfterContentInit 之后变量未定义?

Angular 2 中的 ChangeDetectionStrategy.OnPush 和 Observable.subscribe

异步管道模板中的局部变量(Angular 2+)

如何将新的 FormGroup 或 FormControl 添加到表单

Angular 4 设置下拉菜单中的选定选项

如何在悬停时向元素添加类?

RxJS:takeUntil() Angular 组件的 ngOnDestroy()

如何在 Angular 2 中链接 HTTP 调用?