Как проверить тип значения, возвращаемого методом в определении класса? - PullRequest
0 голосов
/ 17 марта 2019

В следующем примере Button.js , где создается класс JavaScript :

import htmlToElement from './htmlToElement';

class Button {
  constructor() {
    this._html = htmlToElement('<button>simple html</button>');
  }

  render() {
   return this._html;
  }
}

Вход . / Button.spec.js

describe('Rectangle...', function() {
  it(`should be a class constructor..`, function() {
    // how to test against a specific type?
    expect(new Button().render()).to.be('HTMLButtonElement');
  });
});
// note: mocha and chai are included, jsdom is used also. So the button is rendering.

Как проверить это, если возвращаемое значение функции рендеринга является HTMLButtonElement?

1 Ответ

0 голосов
/ 18 марта 2019

Оказывается, что expect(new Button().render()).to.be.a('HTMLButtonElement') будет работать.

...