This commit is contained in:
2026-04-22 18:54:52 +08:00
commit bc8986e3b2
49 changed files with 20987 additions and 0 deletions

41
tests/base-button.test.js Normal file
View File

@@ -0,0 +1,41 @@
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)
})
})