首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Angular-testing-library -我的测试不会在预期错误的值时失败

Angular-testing-library -我的测试不会在预期错误的值时失败
EN

Stack Overflow用户
提问于 2021-09-21 05:48:02
回答 1查看 34关注 0票数 2

我正在使用angular-testing-library进行组件测试。当expect for fail时,在设置了值之后,我的测试用例不会失败。有谁能帮我吗?(标题,newTitle - @inputs)

代码语言:javascript
复制
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
  });

});
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-09-23 08:05:34

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

代码语言:javascript
复制
 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
  });
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69263946

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档