PolymerElements / test-fixture

21 stars 14 forks source link

[feature] test-fixture-mocha to accept HTML in addition to ID #55

Open sashafirsov opened 6 years ago

sashafirsov commented 6 years ago

Description

As for test author the splitting tested HTML and fixture(id) ( within HTML and test JS module ) become significant inconvenience. It forced to switch between HTML and JS while the size of common identifier (id) is often comparable to size of tested HTML itself

<test-fixture id="SomeElementFixture">
  <template>
    <some-element></some-element>
  </template>
</test-fixture>
someElement = fixture('SomeElementFixture');

Proposed

To pass an HTML string which will be instantiated instead of template body on separate HTML.

someElement = fixture(`<some-element></some-element>`);

Backward compatibe

The original signature with ID as parameter still will be in place. The HTML string could be detected either by presence of '<' character as 1st character of anywhere in string.

Benefits

sashafirsov commented 6 years ago

Extending the test code shortening idea by providing automatic fixture for describeFixture or itFixture:

describeFixture ('<some-element>', function ( ) {...
// beforeEach() will re-populate this.someElementInstance or pass it as parameter to it()

or

describe('<some-element>', function () {
itFixture('<some-element foo="baz"> can receive property `foo`  </some-element>', function ( someEl ){
expect(someElement.foo).to.be.equal('baz');