Socket
Socket
Sign inDemoInstall

@open-wc/chai-dom-equals

Package Overview
Dependencies
Maintainers
2
Versions
104
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@open-wc/chai-dom-equals

Chai Plugin to compare dom and shadow dom trees. Part of open-wc recommendations


Version published
Weekly downloads
21K
increased by2.06%
Maintainers
2
Weekly downloads
 
Created
Source

Testing Chai Dom Equals

Part of Open Web Component Recommendation open-wc Recommendation open-wc

We want to provide a good set of defaults on how to facilitate your web component.

CircleCI BrowserStack Status Renovate enabled

Comparing dom literally is usually not what you want when testing components. Additionally, when using ShadyDOM and/or ShadyCSS there will be additional classes you are not interested in.

::: tip Info This is part of the default open-wc recommendation :::

Manual Setup

Add the following after chai is loaded

import { chai } from '@bundled-es-modules/chai';
import { chaiDomEquals } from '@open-wc/chai-dom-equals';

chai.use(chaiDomEquals);

Test dom of an element

it('has the following dom', async () => {
  const el = await fixture(`<div><!-- comment --><h1>${'Hey'}  </h1>  </div>`);
  expect(el).dom.to.equal('<div><!-- comment --><h1>Hey  </h1>  </div>');
  expect(el).dom.to.semantically.equal('<div><h1>Hey</h1></div>');
});

Test shadow dom of an element

it('has the following shadow dom', async () => {
  const tag = defineCE(class extends HTMLElement {
    constructor() {
      super();
      this.attachShadow({ mode: 'open' });
    }

    connectedCallback() {
      this.shadowRoot.innerHTML = '<p>  shadow content</p> <!-- comment --> <slot></slot>';
    }
  });
  const el = await fixture(`<${tag}></${tag}>`);
  expect(el).shadowDom.to.equal('<p>  shadow content</p> <!-- comment --> <slot></slot>');
  expect(el).shadowDom.to.semantically.equal('<p>shadow content</p><slot>');
});

FAQs

Package last updated on 19 Dec 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc