expect(el.style.cssText).toBe('')
})
+ it('should warn for trailing semicolons', () => {
+ const el = document.createElement('div')
+ patchProp(el, 'style', null, { color: 'red;' })
+ expect(
+ `Unexpected semicolon at the end of 'color' style value: 'red;'`
+ ).toHaveBeenWarned()
+
+ patchProp(el, 'style', null, { '--custom': '100; ' })
+ expect(
+ `Unexpected semicolon at the end of '--custom' style value: '100; '`
+ ).toHaveBeenWarned()
+ })
+
+ it('should not warn for escaped trailing semicolons', () => {
+ const el = document.createElement('div')
+ patchProp(el, 'style', null, { '--custom': '100\\;' })
+ expect(el.style.getPropertyValue('--custom')).toBe('100\\;')
+ })
+
// JSDOM doesn't support custom properties on style object so we have to
// mock it here.
function mockElementWithStyle() {
import { isString, hyphenate, capitalize, isArray } from '@vue/shared'
-import { camelize } from '@vue/runtime-core'
+import { camelize, warn } from '@vue/runtime-core'
type Style = string | Record<string, string | string[]> | null
}
}
+const semicolonRE = /[^\\];\s*$/
const importantRE = /\s*!important$/
function setStyle(
val.forEach(v => setStyle(style, name, v))
} else {
if (val == null) val = ''
+ if (__DEV__) {
+ if (semicolonRE.test(val)) {
+ warn(
+ `Unexpected semicolon at the end of '${name}' style value: '${val}'`
+ )
+ }
+ }
if (name.startsWith('--')) {
// custom property definition
style.setProperty(name, val)