Testing CSS Scoped Attribute Implementation in uni-app
This test suite validates the CSS scoped functionality in uni-app, specifically focusing on the addScoped utility function. The tests ensure proper handling of style tags and scoped attribute addition across different scenarios.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
dcloudio/uni-app
packages/uni-cli-shared/__tests__/cssScoped.spec.ts
import { addScoped } from '../src/vite/plugins/cssScoped'
describe('css scoped', () => {
test('add scoped', () => {
expect(addScoped(`<style></style>`)).toBe(`<style scoped></style>`)
expect(addScoped(`<style lang="scss"></style>`)).toBe(
`<style lang="scss" scoped></style>`
)
expect(addScoped(`<style scoped></style>`)).toBe(`<style scoped></style>`)
expect(
addScoped(`<style></style><style scoped></style><style scoped></style>`)
).toBe(
`<style scoped></style><style scoped></style><style scoped></style>`
)
})
})