2026-05-14 17:12:01 +08:00
|
|
|
// test/component.test.js
|
2026-06-06 11:45:52 +08:00
|
|
|
window.testComponent = async function() {
|
2026-05-14 17:12:01 +08:00
|
|
|
console.log('Testing component.js...');
|
|
|
|
|
|
2026-06-06 11:45:52 +08:00
|
|
|
// 1. Register component
|
|
|
|
|
Component.register('TestComp', container => {
|
|
|
|
|
container.state.msg = 'Component Content';
|
2026-06-10 12:21:29 +08:00
|
|
|
}, Util.makeDom('<div><div id="comp-inner" $text="this.state.msg"></div></div>'));
|
2026-05-14 17:12:01 +08:00
|
|
|
|
2026-06-06 11:45:52 +08:00
|
|
|
// 2. Render component
|
2026-06-08 21:53:55 +08:00
|
|
|
const comp = document.createElement('TestComp');
|
|
|
|
|
comp.id = 'comp-inst';
|
|
|
|
|
document.body.appendChild(comp);
|
2026-05-14 17:12:01 +08:00
|
|
|
|
2026-06-06 11:45:52 +08:00
|
|
|
const instance = $('#comp-inst');
|
|
|
|
|
if (!instance) throw new Error('Component instance not found');
|
2026-05-14 17:12:01 +08:00
|
|
|
|
2026-06-10 12:21:29 +08:00
|
|
|
// Wait for async rendering via MutationObserver
|
|
|
|
|
await new Promise(r => setTimeout(r, 100));
|
2026-06-06 11:45:52 +08:00
|
|
|
|
|
|
|
|
const inner = $('#comp-inner');
|
|
|
|
|
if (!inner || inner.textContent !== 'Component Content') {
|
2026-05-14 17:12:01 +08:00
|
|
|
console.log('Current instance innerHTML:', instance.innerHTML);
|
2026-06-10 12:21:29 +08:00
|
|
|
throw new Error('Component rendering failed. Inner content: ' + (inner ? inner.textContent : 'NOT FOUND'));
|
2026-05-14 17:12:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log('component.js tests passed');
|
|
|
|
|
return true;
|
|
|
|
|
}
|