42 lines
1.3 KiB
JavaScript
42 lines
1.3 KiB
JavaScript
const path = require('path')
|
|
const simulate = require('miniprogram-simulate')
|
|
|
|
describe('app-button', () => {
|
|
test('passes core props to TDesign and re-emits tap events', async () => {
|
|
const id = simulate.load(path.join(process.cwd(), 'components/base/app-button/index'), {
|
|
usingComponents: {
|
|
't-button': path.join(
|
|
process.cwd(),
|
|
'node_modules/tdesign-miniprogram/miniprogram_dist/button/button'
|
|
)
|
|
}
|
|
})
|
|
const comp = simulate.render(id, {
|
|
text: '进入工作台',
|
|
theme: 'danger',
|
|
variant: 'outline'
|
|
})
|
|
const parent = document.createElement('div')
|
|
const tapHandler = jest.fn()
|
|
|
|
comp.attach(parent)
|
|
comp.addEventListener('tap', tapHandler)
|
|
const tree = comp.toJSON()
|
|
const innerButton = tree.children[0]
|
|
|
|
expect(innerButton.tagName).toBe('t-button')
|
|
expect(innerButton.attrs).toEqual(
|
|
expect.arrayContaining([
|
|
expect.objectContaining({ name: 'theme', value: 'danger' }),
|
|
expect.objectContaining({ name: 'variant', value: 'outline' })
|
|
])
|
|
)
|
|
expect(innerButton.children).toContain('进入工作台')
|
|
|
|
comp.instance.handleTap({ detail: { source: 'unit-test' } })
|
|
await Promise.resolve()
|
|
|
|
expect(tapHandler).toHaveBeenCalledTimes(1)
|
|
})
|
|
})
|