Search code examples
polymerchaipolymer-2.xweb-component-tester

Can Polymer's web-component-tester use the Chai API?


I have this fixture that stamps out <page-welcome>:

<test-fixture id="fixture-one">
    <template>
        <page-welcome></page-welcome>
    </template>
</test-fixture>

Within <page-welcome>, I import <paper-button> and give it a class of big-btn. It's important this button exists on the <page-welcome> element, so I want to test it with:

    test('does the custom cmponent exist', function() {
        var test = fixture('fixture-one').shadowRoot.querySelector('.big-btn');
        assert.exists(test);
    });

It's my understanding that I should be able to use all of the Chai API, and therefore assert.exists should be available.

But why do I get the following error?

assert.exists is not a function

Solution

  • web-component-tester uses chai 3.5.0, which does not include assert.exists.

    Note that chai's git history shows the introduction of assert.exists in 4.0.0-canary-2 (it seems undocumented in the release notes). You can install this version of chai as a devDependency without breaking anything:

    bower i -D chai
    

    Select the newer/4.x version (currently 4.0.2) when bower prompts for version resolution:

    Unable to find a suitable version for chai, please choose one by typing one of the numbers below:
        1) chai#^3.2.0 which resolved to 3.5.0 and is required by web-component-tester#6.0.0
        2) chai#^4.0.2 which resolved to 4.0.2
    
    Prefix the choice with ! to persist it to bower.json
    
    ? Answer