37 lines
1.3 KiB
JavaScript
37 lines
1.3 KiB
JavaScript
const assert = require('assert')
|
|
const fs = require('fs')
|
|
const path = require('path')
|
|
|
|
let definition
|
|
global.Component = value => { definition = value }
|
|
require('./index')
|
|
|
|
const events = []
|
|
const component = {
|
|
data: {
|
|
items: [{ id: 7, title: '小周' }]
|
|
},
|
|
triggerEvent(name, detail) {
|
|
events.push({ name, detail })
|
|
}
|
|
}
|
|
Object.assign(component, definition.methods)
|
|
|
|
component.onSearch({ detail: { value: '周' } })
|
|
component.selectItem({ currentTarget: { dataset: { index: 0 } } })
|
|
component.retry()
|
|
component.action()
|
|
component.close()
|
|
|
|
assert.deepStrictEqual(events.map(item => item.name), ['search', 'select', 'retry', 'action', 'close'])
|
|
assert.strictEqual(events[0].detail.value, '周')
|
|
assert.strictEqual(events[1].detail.item.id, 7)
|
|
|
|
const wxml = fs.readFileSync(path.join(__dirname, 'index.wxml'), 'utf8')
|
|
const wxss = fs.readFileSync(path.join(__dirname, 'index.wxss'), 'utf8')
|
|
assert.match(wxml, /class="selector-mask"[^>]*catchtouchmove="stopEvent"/)
|
|
assert.match(wxml, /<scroll-view class="selector-scroll" scroll-y/)
|
|
assert.doesNotMatch(wxml, /selector-scroll[^>]*catchtouchmove/)
|
|
assert.match(wxss, /\.selector-sheet\s*\{[^}]*height:\s*88vh;[^}]*flex-direction:\s*column;[^}]*overflow:\s*hidden;/s)
|
|
assert.match(wxss, /\.selector-scroll\s*\{[^}]*min-height:\s*0;[^}]*flex:\s*1;/s)
|