GithubHelp home page GithubHelp logo

ava-webcomponents's Introduction

ava-webcomponents

Utility middleware for testing web components in AVA via Puppeteer.

Travis   npm   License MIT   code style: prettier

npm: npm install ava-webcomponents
yarn: yarn add ava-webcomponents

Getting Started

Create a file that renders content to the screen – such as a web component:

class Hello extends HTMLElement {
    connectedCallback() {
        this.innerHTML = 'Hello AVA!';
    }
}

customElements.define('x-ava', Hello);

Use ava-webcomponents to import the file in your AVA test, which then gives you access to the Puppeteer page variable, as well as a util function for awaiting upgrade of a defined web component.

All imports in your web component file will be resolved relative to the nearest package.json file, which uses a simple Express server instance to import your files.

import test from 'ava';
import withComponent from 'ava-webcomponents';

test(
    'It should render "Hello AVA!";',
    withComponent(`${__dirname}/helpers/example.js`),
    async (t, { page, utils }) => {
        await utils.waitForUpgrade('x-ava');

        const content = await page.evaluate(() => {
            const node = document.createElement('x-ava');
            document.body.append(node);
            return node.innerHTML;
        });

        t.is(content, 'Hello AVA!');
    }
);

With the second argument of the withComponent function you can pass options for puppeteer.launch. However there's also a shortcut for debugging Puppeteer by using withComponent.debug which slows down the tests, opens the devtools, and prevents Chromium from being headless.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.