Module: testing

Enables and implements a basic testing system for custom elements. This uses JSDOM and some hacks to allow you to test your custom elements using a DOM-like experience, but without having to run a real browser. It is designed to have very few dependencies to ensure the least amount of configuration and tool debt.

It assumes you are using Mocha. To create a test, create a file named Whatever.spec.js in the folder where you are running Mocha. Convention is that Whatever is the name of your custom element's class.

Source:
Example
import { withHTML } from "../src/testing/index.js"

describe("<some-element>", () => {
  withHTML(`
  <some-element>OK</some-element>
  `).test("lower-cases its contents", ({document,assert}) => {
    const element = document.querySelector("some-element")
    assert.equal(element.textContent,"ok")
  })
})

Methods

(inner) createTestBasedOnHTML(html, assetMetadata, publicRoot)

Bootstraps a test based on some HTML and configuration about where the bundled custom elements are. It's recommended that you create the method withHTML in your SpecHelper.js file to set up the asset metadata stuff.

This returns a module:testing~CustomElementTest, on which you can call additional setup methods, or start defining tests with the module:testing~CustomElementTest#test method.

Parameters:
Name Type Description
html String

HTML that should be in the document for the test

assetMetadata Object

a JSON object describing where the bundles are. This is needed to allow JSDOM to load the custom elements as if it were served up by a webserver

publicRoot String

The root to where JS files. When using this in a BrutRB web app, this would be where your bundled files are placed for serving.

Source:
See:
  • module:testing~CustomElementTest