Back to Repositories

Validating HTML Entity Transformation in uni-app Compiler Tests

This test suite validates the handling of HTML entities in the uni-app compiler’s transformation process. It ensures proper preservation and processing of special characters and spacing entities during component compilation.

Test Coverage Overview

The test suite focuses on entity preservation during compilation, specifically targeting HTML special characters and spacing entities.

Key areas covered include:
  • HTML special characters (<, >)
  • Spacing entities ( ,  ,  ,  )
  • Text component transformation

Implementation Analysis

The testing approach utilizes Jest’s describe/test pattern with custom assertion utilities. The implementation verifies entity handling within text components, ensuring the compiler maintains entity integrity during transformation.

Technical patterns include:
  • Custom assert utility integration
  • Template string comparison
  • Context object validation

Technical Details

Testing infrastructure includes:
  • Jest test framework
  • Custom testUtils assertion library
  • TypeScript implementation
  • Compiler transformation hooks
  • Entity preservation validation

Best Practices Demonstrated

The test implementation showcases strong testing practices through isolated component testing and explicit expected outputs. Notable practices include:
  • Explicit entity enumeration
  • Isolated transformation testing
  • Clear input/output validation
  • Context object verification

dcloudio/uni-app

packages/uni-mp-compiler/__tests__/entities.spec.ts

            
import { assert } from './testUtils'

describe('compiler: transform entities', () => {
  test('keep entites', () => {
    assert(
      `<text><>    </text>`,
      `<text><>    </text>`,
      `(_ctx, _cache) => {
  const __returned__ = {}
  return __returned__
}`,
      {
        isX: true,
      }
    )
  })
})