首页 > 解决方案 > 我正在寻找一种通过茉莉花测试我的角度组件功能的方法,但不知道如何检查简单的切换功能

问题描述

  showUserInfo(id: number) {
    this.usuarioSelecionado = id;
    this.mostrarConteudo = this.mostrarConteudo ? false : true;
  }

我在规范中这样做,试图传递一个布尔值但没有成功:

it('show more informations about the user', () => {

    expect(this.component.mostrarUsuarioInfo(this.id)).toBe('true')
  });

标签: angulartestingjasmine

解决方案


toBe('true')不检查booleanvalue 而是检查 a stringof value "true"。为了检查布尔值,删除撇号。

it('show more informations about the user', () => {
    expect(this.component.mostrarUsuarioInfo(this.id)).toBe(true);
});

推荐阅读