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

refactor(render): 补充组合式 API

上级 78f20dcb
......@@ -711,9 +711,15 @@
}
},
{
"path": "pages/render-function/render/render",
"path": "pages/render-function/render/render-options",
"style": {
"navigationBarTitleText": "render function"
"navigationBarTitleText": "render 选项式 API"
}
},
{
"path": "pages/render-function/render/render-composition",
"style": {
"navigationBarTitleText": "render 组合式 API"
}
},
{
......
......@@ -976,7 +976,18 @@ export default {
{
id: 'render',
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',
......
<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', () => {
if (process.env.uniTestPlatformInfo.startsWith('web')) {
// TODO: web 端测试未获取到元素
it('web', async () => {
expect(1).toBe(1)
})
describe('render-function render', () => {
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isWeb = platformInfo.startsWith('web')
const isIos = platformInfo.startsWith('ios')
if (isWeb) {
it("web platform test cannot get render dom", async () => {
expect(1).toBe(1);
});
return
}
let page
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
const test = async (pagePath) => {
page = await program.reLaunch(pagePath)
await page.waitFor('view')
})
it('component', async () => {
const ComForRenderFunction = await page.$('.component-for-h-function')
expect(await ComForRenderFunction.text()).toEqual(
'component for h()'
)
const compSlot = await page.$('.comp-slot')
expect(await compSlot.text()).toEqual('component slot')
})
it('text', async () => {
const msgEl = await page.$('.msg')
let msgEl = await page.$('.msg')
expect(await msgEl.text()).toEqual('default msg')
})
it('button', async () => {
const btnEl = await page.$('.btn')
expect(await btnEl.property('type')).toBe('primary')
await btnEl.tap()
const msgEl = await page.$('.msg')
msgEl = await page.$('.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.
先完成此消息的编辑!
想要评论请 注册