Skip to content

Commit

Permalink
typescript parsing support
Browse files Browse the repository at this point in the history
  • Loading branch information
thescientist13 committed Jun 18, 2024
1 parent 779b0c3 commit edbff18
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
11 changes: 11 additions & 0 deletions test/cases/ts/src/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import './greeting.ts';

export default class App extends HTMLElement {
connectedCallback() {
this.innerHTML = `
<wcc-greeting name="WCC"></wcc-greeting>
`;
}
}

customElements.define('wcc-app', App);
17 changes: 17 additions & 0 deletions test/cases/ts/src/greeting.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
interface User {
name: string;
}

export default class Greeting extends HTMLElement {
connectedCallback() {
const user: User = {
name: this.getAttribute('name') || 'World'
};

this.innerHTML = `
<h3>Hello ${user.name}!</h3>
`;
}
}

customElements.define('wcc-greeting', Greeting);
44 changes: 44 additions & 0 deletions test/cases/ts/ts.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Use Case
* Run wcc against a custom elements using TypeScript
*
* User Result
* Should return the expected HTML and JavaScript output.
*
* User Workspace
* src/
* greeting.ts
* app.ts
*/
import chai from 'chai';
import { JSDOM } from 'jsdom';
import { renderToString } from '../../../src/wcc.js';

const expect = chai.expect;

describe('Run WCC For ', function() {
const LABEL = 'Single Custom Element using JSX';
let dom;

before(async function() {
const { html } = await renderToString(new URL('./src/app.ts', import.meta.url));

dom = new JSDOM(html);
});

describe(LABEL, function() {

describe('Greeting component in TypeScript', function() {
let headings;

before(async function() {
headings = dom.window.document.querySelectorAll('h3');
});

it('should server render the expected greeting', () => {
expect(headings.length).to.equal(1);
expect(headings[0].textContent).to.equal('Hello WCC!');
});
});
});
});

0 comments on commit edbff18

Please sign in to comment.