[ci] format

This commit is contained in:
matthewp 2022-05-16 16:17:25 +00:00 committed by github-actions[bot]
parent fe61e469b2
commit 77beab072f

View file

@ -1,67 +1,72 @@
import { expect } from 'chai'; import { expect } from 'chai';
import server from '../server.js' import server from '../server.js';
import { LitElement, html } from 'lit' import { LitElement, html } from 'lit';
import * as cheerio from 'cheerio' import * as cheerio from 'cheerio';
const { check, renderToStaticMarkup } = server const { check, renderToStaticMarkup } = server;
describe('check', () => { describe('check', () => {
it('should be false with no component', async () => { it('should be false with no component', async () => {
expect(await check()).to.equal(false) expect(await check()).to.equal(false);
}) });
it('should be false with a registered non-lit component', async () => { it('should be false with a registered non-lit component', async () => {
const tagName = 'non-lit-component' const tagName = 'non-lit-component';
customElements.define(tagName, class TestComponent extends HTMLElement {}) customElements.define(tagName, class TestComponent extends HTMLElement {});
expect(await check(tagName)).to.equal(false) expect(await check(tagName)).to.equal(false);
}) });
it('should be true with a registered lit component', async () => { it('should be true with a registered lit component', async () => {
const tagName = 'lit-component' const tagName = 'lit-component';
customElements.define(tagName, class extends LitElement {}) customElements.define(tagName, class extends LitElement {});
expect(await check(tagName)).to.equal(true) expect(await check(tagName)).to.equal(true);
}) });
}) });
describe('renderToStaticMarkup', () => { describe('renderToStaticMarkup', () => {
it('should throw error if trying to render an unregistered component', async () => { it('should throw error if trying to render an unregistered component', async () => {
const tagName = 'non-registrered-component' const tagName = 'non-registrered-component';
try { try {
await renderToStaticMarkup(tagName) await renderToStaticMarkup(tagName);
} catch (e) { } catch (e) {
expect(e).to.be.an.instanceOf(TypeError) expect(e).to.be.an.instanceOf(TypeError);
} }
}) });
it('should render emtpy component with default markup', async () => { it('should render emtpy component with default markup', async () => {
const tagName = 'nothing-component' const tagName = 'nothing-component';
customElements.define(tagName, class extends LitElement {}) customElements.define(tagName, class extends LitElement {});
const render = await renderToStaticMarkup(tagName) const render = await renderToStaticMarkup(tagName);
expect(render).to.deep.equal({ expect(render).to.deep.equal({
html: `<${tagName}><template shadowroot="open"><!--lit-part--><!--/lit-part--></template></${tagName}>` html: `<${tagName}><template shadowroot="open"><!--lit-part--><!--/lit-part--></template></${tagName}>`,
}) });
}) });
it('should render component with default markup', async () => { it('should render component with default markup', async () => {
const tagName = 'simple-component' const tagName = 'simple-component';
customElements.define(tagName, class extends LitElement { customElements.define(
tagName,
class extends LitElement {
render() { render() {
return html`<p>hola</p>` return html`<p>hola</p>`;
} }
}) }
const render = await renderToStaticMarkup(tagName) );
const $ = cheerio.load(render.html) const render = await renderToStaticMarkup(tagName);
expect($(`${tagName} template`).html()).to.contain('<p>hola</p>') const $ = cheerio.load(render.html);
}) expect($(`${tagName} template`).html()).to.contain('<p>hola</p>');
});
it('should render component with properties and attributes', async () => { it('should render component with properties and attributes', async () => {
const tagName = 'props-and-attrs-component' const tagName = 'props-and-attrs-component';
const attr1 = 'test' const attr1 = 'test';
const prop1 = 'Daniel' const prop1 = 'Daniel';
customElements.define(tagName, class extends LitElement { customElements.define(
tagName,
class extends LitElement {
static properties = { static properties = {
prop1: { type: String }, prop1: { type: String },
} };
constructor() { constructor() {
super(); super();
@ -69,12 +74,13 @@ describe('renderToStaticMarkup', () => {
} }
render() { render() {
return html`<p>Hello ${this.prop1}</p>` return html`<p>Hello ${this.prop1}</p>`;
} }
}) }
const render = await renderToStaticMarkup(tagName, { prop1, attr1 }) );
const $ = cheerio.load(render.html) const render = await renderToStaticMarkup(tagName, { prop1, attr1 });
expect($(tagName).attr('attr1')).to.equal(attr1) const $ = cheerio.load(render.html);
expect($(`${tagName} template`).text()).to.contain(`Hello ${prop1}`) expect($(tagName).attr('attr1')).to.equal(attr1);
}) expect($(`${tagName} template`).text()).to.contain(`Hello ${prop1}`);
}) });
});