Testing Page Route Metadata Configuration in uni-app
This test suite validates the page route metadata initialization functionality in uni-app, focusing on navigation bar configuration and pull-to-refresh features. The tests ensure proper handling of default configurations and custom overrides for page-specific settings.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
dcloudio/uni-app
packages/uni-core/__tests__/helpers/page.spec.ts
import { initRouteMeta } from '../../src/helpers/page'
function initDefaultUniConfig() {
return JSON.parse(
JSON.stringify({
globalStyle: {
navigationBar: {},
},
})
)
}
describe('page', () => {
test('initRouteMeta', () => {
global.__uniConfig = initDefaultUniConfig()
global.__uniConfig.globalStyle.navigationBar.titleText = 'uni-app'
expect(
initRouteMeta(
{
route: '',
navigationBar: {},
},
1
)
).toMatchSnapshot()
expect(
initRouteMeta(
{
route: '',
navigationBar: { titleText: 'hello', titleColor: '#000000' },
enablePullDownRefresh: true,
},
1
)
).toMatchSnapshot()
expect(
initRouteMeta(
{
route: '',
navigationBar: { titleColor: '#000000' },
enablePullDownRefresh: true,
pullToRefresh: {
offset: 100,
},
},
1
)
).toMatchSnapshot()
})
})