提交 6e761430 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

refactor(render): 补充组合式 API

上级 78f20dcb
...@@ -711,9 +711,15 @@ ...@@ -711,9 +711,15 @@
} }
}, },
{ {
"path": "pages/render-function/render/render", "path": "pages/render-function/render/render-options",
"style": { "style": {
"navigationBarTitleText": "render function" "navigationBarTitleText": "render 选项式 API"
}
},
{
"path": "pages/render-function/render/render-composition",
"style": {
"navigationBarTitleText": "render 组合式 API"
} }
}, },
{ {
......
...@@ -976,7 +976,18 @@ export default { ...@@ -976,7 +976,18 @@ export default {
{ {
id: 'render', id: 'render',
name: 'render & h()', name: 'render & h()',
url: 'render/render' children: [
{
id: 'render-options',
name: 'render 选项式 API',
url: 'render-options'
},
{
id: 'render-composition',
name: 'render 组合式 API',
url: 'render-composition'
},
]
}, },
{ {
id: 'mergeProps', id: 'mergeProps',
......
<script setup lang="uts">
import CompForHFunction from '@/components/CompForHFunction.uvue'
defineOptions({
data() {
return {
msg: 'default msg'
}
},
render(): VNode {
const instance = getCurrentInstance()!.proxy!
return h('view', { class: 'page' }, [
h(CompForHFunction, {}, (): VNode[] => [h('text', { class: 'comp-slot' }, 'component slot')]),
h('text', { class: 'uni-common-mt msg', style: { color: 'blue' } }, instance.$data['msg']),
h(
'button',
{
class: 'uni-common-mt btn',
type: 'primary',
onClick: () => {
instance.$data['msg'] = 'new msg'
}
},
'click'
)
])
}
})
</script>
<style>
.btn {
color: red;
}
</style>
\ No newline at end of file
const PAGE_PATH = '/pages/render-function/render/render' const OPTIONS_PAGE_PATH = '/pages/render-function/render/render-options'
const COMPOSITION_PAGE_PATH = '/pages/render-function/render/render-composition'
describe('/pages/render-function/render/render', () => { describe('render-function render', () => {
if (process.env.uniTestPlatformInfo.startsWith('web')) { const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
// TODO: web 端测试未获取到元素 const isWeb = platformInfo.startsWith('web')
it('web', async () => { const isIos = platformInfo.startsWith('ios')
expect(1).toBe(1) if (isWeb) {
}) it("web platform test cannot get render dom", async () => {
expect(1).toBe(1);
});
return return
} }
let page let page
beforeAll(async () => { const test = async (pagePath) => {
page = await program.reLaunch(PAGE_PATH) page = await program.reLaunch(pagePath)
await page.waitFor('view') await page.waitFor('view')
})
it('component', async () => {
const ComForRenderFunction = await page.$('.component-for-h-function') const ComForRenderFunction = await page.$('.component-for-h-function')
expect(await ComForRenderFunction.text()).toEqual( expect(await ComForRenderFunction.text()).toEqual(
'component for h()' 'component for h()'
) )
const compSlot = await page.$('.comp-slot') const compSlot = await page.$('.comp-slot')
expect(await compSlot.text()).toEqual('component slot') expect(await compSlot.text()).toEqual('component slot')
})
it('text', async () => { let msgEl = await page.$('.msg')
const msgEl = await page.$('.msg')
expect(await msgEl.text()).toEqual('default msg') expect(await msgEl.text()).toEqual('default msg')
})
it('button', async () => {
const btnEl = await page.$('.btn') const btnEl = await page.$('.btn')
expect(await btnEl.property('type')).toBe('primary') expect(await btnEl.property('type')).toBe('primary')
await btnEl.tap() await btnEl.tap()
const msgEl = await page.$('.msg') msgEl = await page.$('.msg')
expect(await msgEl.text()).toEqual('new msg') expect(await msgEl.text()).toEqual('new msg')
}
it('render options API', async () => {
await test(OPTIONS_PAGE_PATH)
})
it('render composition API', async () => {
if (!isIos) {
await test(COMPOSITION_PAGE_PATH)
} else {
// TODO: ios 端 defineOptions + render 页面空白
expect(1).toBe(1);
}
}) })
}) })
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册