2

我正在使用angular-testing-library我的组件测试。当期望失败时,设置值后,我的测试用例没有失败。有人帮我吗?(标题,新标题-@inputs)

import { render, screen } from '@testing-library/angular';
import userEvent from "@testing-library/user-event";
import { UserViewComponent } from './user-view.component';
import { provideMockStore } from "@ngrx/store/testing";
import { RouterTestingModule } from '@angular/router/testing';
import { ShellUserViewComponent } from '../../containers/shell-user-view/shell-user-view.component';
import { of } from 'rxjs';


describe('ShellUserViewComponent', () => {

  beforeEach(async () => {
    await render(ShellUserViewComponent, {
      componentProperties: {
        title: "welcome to Chennai",
        newTitle: "new title for test",
        users$: of([])
      },
      imports: [RouterTestingModule],
      declarations: [UserViewComponent],
      providers: [provideMockStore({})]
    });
  })

  it('should find the welcome as title', () => {
    expect(screen.findByText(/welcome to Chennaicc/i)).toBeTruthy(); //not failing cc added
    expect(screen.findByText(/new title for testx/i)).toBeTruthy(); //not failing x added
  });

});
4

1 回答 1

1

findBy 是异步的,所以你需要等待它

 it('should find the welcome as title', async () => {
    expect(await screen.findByText(/welcome to Chennaicc/i)).toBeTruthy(); //not failing cc added
    expect(await screen.findByText(/new title for testx/i)).toBeTruthy(); //not failing x added
  });
于 2021-09-23T08:05:34.450 回答