Testing DOM Selector Query Implementation in uni-app
This test suite validates the DOM selector query functionality in uni-app’s platform-specific implementation. It ensures proper method definitions and NodesRef interface compliance for DOM element selection and manipulation.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
dcloudio/uni-app
packages/uni-app-plus/__tests__/x/api/dom/createSelectorQuery.spec.ts
import { createSelectorQuery } from '../../../../src/x/api/dom/createSelectorQuery'
// import { getCurrentPage } from '@dcloudio/uni-core'
jest.mock('@dcloudio/uni-core', () => {
return {
getCurrentPage: jest.fn(() => {
return {
vm: null,
}
}),
}
})
describe('createSelectorQuery', () => {
it('定义包含的方法', () => {
const query = createSelectorQuery()
expect(typeof query.in).toBe('function')
expect(typeof query.select).toBe('function')
expect(typeof query.selectAll).toBe('function')
expect(typeof query.selectViewport).toBe('function')
expect(typeof query.exec).toBe('function')
})
it('NodesRef 定义的方法', () => {
const query = createSelectorQuery()
const ref = query.select('.test')
expect(typeof ref.boundingClientRect).toBe('function')
expect(typeof ref.scrollOffset).toBe('function')
expect(typeof ref.fields).toBe('function')
expect(typeof ref.context).toBe('function')
expect(typeof ref.node).toBe('function')
})
})