可能是因为在测试过程中未正确引用断言库(例如Jasmine),以确保正确的断言用于期望的输出。
以下是一个示例,展示如何在使用Angular测试库和Jasmine的情况下测试简单组件的正确输出:
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { MyComponent } from './my.component';
describe('MyComponent', () => {
  let component: MyComponent;
  let fixture: ComponentFixture;
  beforeEach(async () => {
    await TestBed.configureTestingModule({
      declarations: [ MyComponent ]
    })
    .compileComponents();
  });
  beforeEach(() => {
    fixture = TestBed.createComponent(MyComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });
  it('should create', () => {
    expect(component).toBeTruthy();
  });
  it('should display the correct title', () => {
    const expectedTitle = 'My Title';
    const titleElement = fixture.nativeElement.querySelector('h1');
    expect(titleElement.textContent).toEqual(expectedTitle);
  });
});
 在上面的示例中,我们使用Jasmine的expect语法进行期望输出的断言。如果我们期望的输出不正确,测试就会失败,并且在控制台中展示错误信息。
请确保您的测试文件正确引用了您需要使用的断言库,并检查代码中是否存在其他可能阻止失败的问题。
                    上一篇:angular-summernote: 在代码视图模式下,光标在输入时会跳到文本的末尾
                
下一篇:angular-testing-library: getByRole 查询只在使用 hidden: true 选项时有效。