typescript NGX-易于测试zippy.component.spec.ts

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了typescript NGX-易于测试zippy.component.spec.ts相关的知识,希望对你有一定的参考价值。

import { createHost, EasyTestWithHost } from 'ngx-easy-test';

describe('ZippyComponent', () => {
  type Context = EasyTestWithHost<ZippyComponent>;

  createHost(ZippyComponent);

  it('should display the title', function ( this : Context ) {
    this.create(`<zippy title="Zippy title"></zippy>`);
    expect(this.query('.zippy__title')).toContainText('Zippy title');
  });

  it('should display the content', function ( this : Context ) {
    this.create(`<zippy title="Zippy title">Zippy content</zippy>`);
    this.trigger('click', '.zippy__title');
    expect(this.query('.zippy__content')).toContainText('Zippy content');
  });

  it('should display the "Open" word if closed', function ( this : Context ) {
    this.create(`<zippy title="Zippy title">Zippy content</zippy>`);
    expect(this.query('.arrow')).toContainText('Open');
    expect(this.query('.arrow')).not.toContainText('Close');
  });

  it('should display the "Close" word if open', function ( this : Context ) {
    this.create(`<zippy title="Zippy title">Zippy content</zippy>`);
    this.trigger('click', '.zippy__title');
    expect(this.query('.arrow')).toContainText('Close');
    expect(this.query('.arrow')).not.toContainText('Open');
  });

  it('should be closed by default', function ( this : Context ) {
    this.create(`<zippy title="Zippy title"></zippy>`);
    expect('.zippy__content').not.toBeInDOM();
  });

  it('should toggle the content', function ( this : Context ) {
    this.create(`<zippy title="Zippy title"></zippy>`);
    this.trigger('click', '.zippy__title');
    expect('.zippy__content').toBeInDOM();
    this.trigger('click', '.zippy__title');
    expect('.zippy__content').not.toBeInDOM();
  });

});

以上是关于typescript NGX-易于测试zippy.component.spec.ts的主要内容,如果未能解决你的问题,请参考以下文章

typescript NGX-易于测试button.component.ts

typescript NGX-易于测试button.component.spec.ts

typescript zippy.component.spec.ts

Typescript 代码在调试单元测试时启用了覆盖率

无法使用 ngx translate/core - angular 2 typescript 获得文本的动态翻译

BUU-MISC-[BSidesSF2019]zippy