example.test.tsx 613 B

123456789101112131415161718192021222324252627
  1. import TestUtils from '@tarojs/test-utils-react'
  2. import React from 'react'
  3. const testUtils = new TestUtils()
  4. // 简单的测试组件
  5. const TestComponent = () => {
  6. return (
  7. <view className="test-component">
  8. <text className="btn">点击我</text>
  9. </view>
  10. )
  11. }
  12. describe('Taro Test Utils Example', () => {
  13. it('应该正确渲染组件', async () => {
  14. await testUtils.mount(TestComponent)
  15. const btn = await testUtils.queries.waitForQuerySelector('.btn')
  16. await testUtils.act(() => {
  17. testUtils.fireEvent.click(btn)
  18. })
  19. expect(testUtils.html()).toMatchSnapshot()
  20. })
  21. })