init
This commit is contained in:
41
tests/base-button.test.js
Normal file
41
tests/base-button.test.js
Normal 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)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user