Type of Change
- Other (please clarify below)
Summary
As part of #44 , I tried adding test cases to the PR, but they kept failing, and I think it is related to #24 .
Details
Would like to add a test case though to ensure this works as expected ASAP. Here is what I had originally - #44
Make sure to install node-fetch as a devDependency
// ./components/events-list.js
import fetch from 'node-fetch';
class EventsList extends HTMLElement {
async connectedCallback() {
if (!this.shadowRoot) {
// TODO should probably try and make this a JSON file
const events = await fetch('http://www.analogstudios.net/api/v2/events').then(resp => resp.json());
this.attachShadow({ mode: 'open' });
this.shadowRoot.innerHTML = `<h1>Events List (${events.length})</h1>`;
}
}
}
export {
EventsList
};
customElements.define('wc-events-list', EventsList);
// index.js
import './components/events-list.js';
export default class HomePage extends HTMLElement {
constructor() {
super();
if (this.shadowRoot) {
// console.debug('HomePage => shadowRoot detected!');
} else {
this.attachShadow({ mode: 'open' });
}
}
connectedCallback() {
this.shadowRoot.innerHTML = this.getTemplate();
}
getTemplate() {
return `
<wc-events-list></wc-events-list>
`;
}
}
// node-modules.spec.js
/*
* Use Case
* Run wcc against a custom element using a dependency from node-modules
*
* User Result
* Should run without error.
*
* User Workspace
* src/
* components/
* events-list.js
* index.js
*/
import { renderToString } from '../../../src/wcc.js';
describe('Run WCC For ', function() {
const LABEL = 'Custom Element w/ a node modules dependency';
describe(LABEL, function() {
it('should not fail when the content load a node module', function() {
Promise.resolve(renderToString(new URL('./src/index.js', import.meta.url)));
});
});
});
Type of Change
Summary
As part of #44 , I tried adding test cases to the PR, but they kept failing, and I think it is related to #24 .
Details
Would like to add a test case though to ensure this works as expected ASAP. Here is what I had originally - #44