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

Posted

tags:

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

import { ButtonComponent } from './button.component';
import { EasyTest, easyTest } from 'ngx-easy-test';

describe('ButtonComponent', () => {

  type Context = EasyTest<ButtonComponent>;

  easyTest(ButtonComponent);

  it('should set the "success" class by default', function ( this : Context ) {
    expect(this.query('button')).toHaveClass('success');
  });

  it('should set the class name according to the [className]', function ( this : Context ) {
    this.whenInput({ className: 'danger' });
    expect(this.query('button')).toHaveClass('danger');
    expect(this.query('button')).not.toHaveClass('success');
  });

  it('should set the title according to the [title]', function ( this : Context ) {
    this.whenInput('title', 'Click');
    expect(this.query('button')).toContainText('Click');
  });

  it('should emit the $event on click', function ( this : Context ) {
    let output;
    this.whenOutput<{ type: string }>('click', result => output = result);
    this.trigger('click', 'button', { type: 'click' });
    expect(output).toEqual({ type: 'click' });
  });

});

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

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

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

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

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

使用ngx-datatable删除行

更新角度4.4到6后,缺少TypeScript编译错误