From 89df4b9808b14dde8854397ffe998901dd8529b5 Mon Sep 17 00:00:00 2001 From: lnuxe Date: Tue, 10 Nov 2026 15:51:52 +0800 Subject: [PATCH] fix: #34 nested components with absolute usingComponents path are not rendered --- docs/detail.md | 2 +- docs/update.md | 4 ++ package-lock.json | 4 +- package.json | 2 +- src/index.js | 55 ++++++++++++++++++- test/comp12/components/main-status/index.js | 8 +++ test/comp12/components/main-status/index.json | 6 ++ test/comp12/components/main-status/index.wxml | 4 ++ test/comp12/components/main-status/index.wxss | 4 ++ test/comp12/components/u-icon/index.js | 8 +++ test/comp12/components/u-icon/index.json | 3 + test/comp12/components/u-icon/index.wxml | 1 + test/comp12/components/u-icon/index.wxss | 4 ++ test/comp12/index.test.js | 35 ++++++++++++ test/comp12/page/index.js | 5 ++ test/comp12/page/index.json | 6 ++ test/comp12/page/index.wxml | 3 + test/comp12/page/index.wxss | 3 + 18 files changed, 151 insertions(+), 6 deletions(-) create mode 100644 test/comp12/components/main-status/index.js create mode 100644 test/comp12/components/main-status/index.json create mode 100644 test/comp12/components/main-status/index.wxml create mode 100644 test/comp12/components/main-status/index.wxss create mode 100644 test/comp12/components/u-icon/index.js create mode 100644 test/comp12/components/u-icon/index.json create mode 100644 test/comp12/components/u-icon/index.wxml create mode 100644 test/comp12/components/u-icon/index.wxss create mode 100644 test/comp12/index.test.js create mode 100644 test/comp12/page/index.js create mode 100644 test/comp12/page/index.json create mode 100644 test/comp12/page/index.wxml create mode 100644 test/comp12/page/index.wxss diff --git a/docs/detail.md b/docs/detail.md index 2153bbe..7a7d5b0 100644 --- a/docs/detail.md +++ b/docs/detail.md @@ -56,7 +56,7 @@ simulate.load('/comp', 'custom-comp') // 渲染出来的结果是 + + {{msg}} + diff --git a/test/comp12/components/main-status/index.wxss b/test/comp12/components/main-status/index.wxss new file mode 100644 index 0000000..8b904c5 --- /dev/null +++ b/test/comp12/components/main-status/index.wxss @@ -0,0 +1,4 @@ +.main--status { + color: #1e6bb8; + font-size: 16px; +} diff --git a/test/comp12/components/u-icon/index.js b/test/comp12/components/u-icon/index.js new file mode 100644 index 0000000..8f7479a --- /dev/null +++ b/test/comp12/components/u-icon/index.js @@ -0,0 +1,8 @@ +Component({ + properties: { + name: { + type: String, + value: 'icon', + }, + }, +}) diff --git a/test/comp12/components/u-icon/index.json b/test/comp12/components/u-icon/index.json new file mode 100644 index 0000000..10e7f9d --- /dev/null +++ b/test/comp12/components/u-icon/index.json @@ -0,0 +1,3 @@ +{ + "component": true +} diff --git a/test/comp12/components/u-icon/index.wxml b/test/comp12/components/u-icon/index.wxml new file mode 100644 index 0000000..225917f --- /dev/null +++ b/test/comp12/components/u-icon/index.wxml @@ -0,0 +1 @@ +[{{name}}] diff --git a/test/comp12/components/u-icon/index.wxss b/test/comp12/components/u-icon/index.wxss new file mode 100644 index 0000000..2496dd4 --- /dev/null +++ b/test/comp12/components/u-icon/index.wxss @@ -0,0 +1,4 @@ +.u-icon { + color: #e64340; + font-weight: bold; +} diff --git a/test/comp12/index.test.js b/test/comp12/index.test.js new file mode 100644 index 0000000..e498db3 --- /dev/null +++ b/test/comp12/index.test.js @@ -0,0 +1,35 @@ +const path = require('path') +const simulate = require('../../index') + +function runTest(id) { + const comp = simulate.render(id) + + const parent = document.createElement('parent-wrapper') + comp.attach(parent) + + // 嵌套的自定义组件需要渲染出自身模板,而不是停留在空节点 + expect(simulate.match(comp.dom, ` + + + + + [star] + + 这是测试文案 + + + + `)).toBe(true) + expect(comp.dom.querySelector('main-status').innerHTML).toBeTruthy() + expect(comp.dom.querySelector('u-icon').innerHTML).toBeTruthy() +} + +test('comp12', () => { + let id = simulate.load(path.resolve(__dirname, './page/index'), 'page') + runTest(id) + + jest.resetModules() // https://github.com/facebook/jest/issues/5120 + + id = simulate.load(path.resolve(__dirname, './page/index'), 'page', {compiler: 'simulate'}) + runTest(id) +}) diff --git a/test/comp12/page/index.js b/test/comp12/page/index.js new file mode 100644 index 0000000..5164b17 --- /dev/null +++ b/test/comp12/page/index.js @@ -0,0 +1,5 @@ +Component({ + data: { + msg: '这是测试文案', + }, +}) diff --git a/test/comp12/page/index.json b/test/comp12/page/index.json new file mode 100644 index 0000000..17e420c --- /dev/null +++ b/test/comp12/page/index.json @@ -0,0 +1,6 @@ +{ + "component": true, + "usingComponents": { + "main-status": "/components/main-status/index" + } +} diff --git a/test/comp12/page/index.wxml b/test/comp12/page/index.wxml new file mode 100644 index 0000000..91f489f --- /dev/null +++ b/test/comp12/page/index.wxml @@ -0,0 +1,3 @@ + + + diff --git a/test/comp12/page/index.wxss b/test/comp12/page/index.wxss new file mode 100644 index 0000000..0009fe6 --- /dev/null +++ b/test/comp12/page/index.wxss @@ -0,0 +1,3 @@ +.page { + padding: 10px; +}