summaryrefslogtreecommitdiff
path: root/packages/integrations/lit/test/server.test.js
diff options
context:
space:
mode:
authorGravatar matthewp <matthewp@users.noreply.github.com> 2022-05-16 16:17:25 +0000
committerGravatar github-actions[bot] <github-actions[bot]@users.noreply.github.com> 2022-05-16 16:17:25 +0000
commit77beab072f6c9f86ea74f2a16f8250da3a06eacc (patch)
tree6c4e2294183050cdb75fb9f144d0c814ecb4e8dc /packages/integrations/lit/test/server.test.js
parentfe61e469b243c27781112499f151782baf9004a4 (diff)
downloadastro-77beab072f6c9f86ea74f2a16f8250da3a06eacc.tar.gz
astro-77beab072f6c9f86ea74f2a16f8250da3a06eacc.tar.zst
astro-77beab072f6c9f86ea74f2a16f8250da3a06eacc.zip
[ci] format
Diffstat (limited to 'packages/integrations/lit/test/server.test.js')
-rw-r--r--packages/integrations/lit/test/server.test.js116
1 files changed, 61 insertions, 55 deletions
diff --git a/packages/integrations/lit/test/server.test.js b/packages/integrations/lit/test/server.test.js
index a4b691209..0769e59d4 100644
--- a/packages/integrations/lit/test/server.test.js
+++ b/packages/integrations/lit/test/server.test.js
@@ -1,80 +1,86 @@
import { expect } from 'chai';
-import server from '../server.js'
-import { LitElement, html } from 'lit'
-import * as cheerio from 'cheerio'
+import server from '../server.js';
+import { LitElement, html } from 'lit';
+import * as cheerio from 'cheerio';
-const { check, renderToStaticMarkup } = server
+const { check, renderToStaticMarkup } = server;
describe('check', () => {
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 () => {
- const tagName = 'non-lit-component'
- customElements.define(tagName, class TestComponent extends HTMLElement {})
- expect(await check(tagName)).to.equal(false)
- })
+ const tagName = 'non-lit-component';
+ customElements.define(tagName, class TestComponent extends HTMLElement {});
+ expect(await check(tagName)).to.equal(false);
+ });
it('should be true with a registered lit component', async () => {
- const tagName = 'lit-component'
- customElements.define(tagName, class extends LitElement {})
- expect(await check(tagName)).to.equal(true)
- })
-})
+ const tagName = 'lit-component';
+ customElements.define(tagName, class extends LitElement {});
+ expect(await check(tagName)).to.equal(true);
+ });
+});
describe('renderToStaticMarkup', () => {
it('should throw error if trying to render an unregistered component', async () => {
- const tagName = 'non-registrered-component'
+ const tagName = 'non-registrered-component';
try {
- await renderToStaticMarkup(tagName)
+ await renderToStaticMarkup(tagName);
} 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 () => {
- const tagName = 'nothing-component'
- customElements.define(tagName, class extends LitElement {})
- const render = await renderToStaticMarkup(tagName)
+ const tagName = 'nothing-component';
+ customElements.define(tagName, class extends LitElement {});
+ const render = await renderToStaticMarkup(tagName);
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 () => {
- const tagName = 'simple-component'
- customElements.define(tagName, class extends LitElement {
- render() {
- return html`<p>hola</p>`
+ const tagName = 'simple-component';
+ customElements.define(
+ tagName,
+ class extends LitElement {
+ render() {
+ return html`<p>hola</p>`;
+ }
}
- })
- const render = await renderToStaticMarkup(tagName)
- const $ = cheerio.load(render.html)
- expect($(`${tagName} template`).html()).to.contain('<p>hola</p>')
- })
+ );
+ const render = await renderToStaticMarkup(tagName);
+ const $ = cheerio.load(render.html);
+ expect($(`${tagName} template`).html()).to.contain('<p>hola</p>');
+ });
it('should render component with properties and attributes', async () => {
- const tagName = 'props-and-attrs-component'
- const attr1 = 'test'
- const prop1 = 'Daniel'
- customElements.define(tagName, class extends LitElement {
- static properties = {
- prop1: { type: String },
- }
+ const tagName = 'props-and-attrs-component';
+ const attr1 = 'test';
+ const prop1 = 'Daniel';
+ customElements.define(
+ tagName,
+ class extends LitElement {
+ static properties = {
+ prop1: { type: String },
+ };
- constructor() {
- super();
- this.prop1 = 'someone';
- }
-
- render() {
- return html`<p>Hello ${this.prop1}</p>`
+ constructor() {
+ super();
+ this.prop1 = 'someone';
+ }
+
+ render() {
+ return html`<p>Hello ${this.prop1}</p>`;
+ }
}
- })
- const render = await renderToStaticMarkup(tagName, { prop1, attr1 })
- const $ = cheerio.load(render.html)
- expect($(tagName).attr('attr1')).to.equal(attr1)
- expect($(`${tagName} template`).text()).to.contain(`Hello ${prop1}`)
- })
-})
+ );
+ const render = await renderToStaticMarkup(tagName, { prop1, attr1 });
+ const $ = cheerio.load(render.html);
+ expect($(tagName).attr('attr1')).to.equal(attr1);
+ expect($(`${tagName} template`).text()).to.contain(`Hello ${prop1}`);
+ });
+});