npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cypress-ct-html

v1.1.0

Published

Cypress Component Testing for plain HTML/CSS/JS and Web Components

Downloads

22

Readme

Cypress Component Testing for HTML elements

"Use all the power of cypress component testing with simple html elements and web components. ⚡"

This package provides configuration and commands for testing html elements with the power of cypress.

Getting started

To install, run:

npm install -D cypress-ct-html

Once you have the package installed alongside Cypress, you can run npx cypress open, choose "Component Testing", and HTML should appear in the list of frameworks available.

Learn more about third-party definitions

Configuration

Add cypress-ct-html framework to your cypress.config.{ts,js} file

export default defineConfig({
    component: {
        devServer: {
            framework: "cypress-ct-html",
            // more config here
        },
    },
});

If you're using TypeScript, you may get a type error when setting the framework property. If so, you'll need to typecast it as any

framework: 'cypress-ct-html' as any,

Adding mount Command

Next, add the following lines to your component.{js.ts}

import { mount } from "cypress-ct-html";

Cypress.Commands.add("mount", mount);

Optionally, this package brings its custom types definitions. Add the following to tsconfig.json or jsconfig.json in your project.

{
    "compilerOptions": {
        // more compiler options...
        "types": ["cypress", "cypress-ct-html"]
    }
}

Usage notes

You can now mount any html element in a component test, for example:

it("should display content", () => {
    const div = document.createElement("div");
    div.textContent = "Hello, World!";
    cy.mount(div);

    cy.get("#content").should("contain.text", "Hello, World!");
});

Or find content inside your web component

import "path/to/my-element";

it("should render its children", () => {
    const myElement = document.createElement("my-element");
    cy.mount(myElement);

    cy.get("my-element").shadow().find(".my-part").should("exist");
});

For more examples and basic usages see ´cypress/component´ examples

Note: You may prefer use includeShadowDom option to avoid write shadow() command on every test.

export default defineConfig({
    includeShadowDom: true,
    component: {
        devServer: {
            framework: "cypress-ct-html",
            // more config here
        },
    },
});

Credits

Much of the code and inspiration for this package comes from the work of redfox-mx and his cypress-lit repository. A big thank you for his contributions to the community.