From: daiwei Date: Thu, 27 Nov 2025 03:05:31 +0000 (+0800) Subject: test: Implement `setClassIncremental` and `setStyleIncremental` tests. X-Git-Tag: v3.6.0-alpha.6~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=05b8dbdb56f7fc2d34d36679eb5a689e7f38e482;p=thirdparty%2Fvuejs%2Fcore.git test: Implement `setClassIncremental` and `setStyleIncremental` tests. --- diff --git a/packages/runtime-vapor/__tests__/dom/prop.spec.ts b/packages/runtime-vapor/__tests__/dom/prop.spec.ts index dd29281bac..a2f49b8759 100644 --- a/packages/runtime-vapor/__tests__/dom/prop.spec.ts +++ b/packages/runtime-vapor/__tests__/dom/prop.spec.ts @@ -188,9 +188,92 @@ describe('patchProp', () => { }) }) - describe.todo('setClassIncremental', () => {}) + describe('setClassIncremental', () => { + test('should set class', () => { + const el = document.createElement('div') + // mark as root + ;(el as any).$root = true + setClass(el, 'foo') + expect(el.className).toBe('foo') + + // Should replace previous class set by setClass + setClass(el, 'bar') + expect(el.className).toBe('bar') + }) + + test('should coexist with existing classes', () => { + const el = document.createElement('div') + el.className = 'existing' + ;(el as any).$root = true + + setClass(el, 'foo') + expect(el.className).toBe('existing foo') + + setClass(el, 'bar') + expect(el.className).toBe('existing bar') + + setClass(el, '') + expect(el.className).toBe('existing') + }) + + test('should handle multiple classes', () => { + const el = document.createElement('div') + ;(el as any).$root = true + + setClass(el, 'foo bar') + expect(el.className).toBe('foo bar') + + setClass(el, 'baz') + expect(el.className).toBe('baz') + }) + }) + + describe('setStyleIncremental', () => { + test('should set style', () => { + const el = document.createElement('div') + ;(el as any).$root = true + setStyle(el, 'color: red') + expect(el.style.cssText).toBe('color: red;') - describe.todo('setStyleIncremental', () => {}) + setStyle(el, 'font-size: 12px') + expect(el.style.cssText).toBe('font-size: 12px;') + }) + + test('should coexist with existing styles', () => { + const el = document.createElement('div') + el.style.display = 'block' + ;(el as any).$root = true + + setStyle(el, 'color: red') + expect(el.style.display).toBe('block') + expect(el.style.color).toBe('red') + + setStyle(el, 'font-size: 12px') + expect(el.style.display).toBe('block') + expect(el.style.fontSize).toBe('12px') + expect(el.style.color).toBe('') + }) + + test('should set style with object', () => { + const el = document.createElement('div') + ;(el as any).$root = true + setStyle(el, { color: 'red' }) + expect(el.style.cssText).toBe('color: red;') + + setStyle(el, { fontSize: '12px' }) + expect(el.style.cssText).toBe('font-size: 12px;') + }) + + test('should remove style', () => { + const el = document.createElement('div') + ;(el as any).$root = true + setStyle(el, 'color: red') + expect(el.style.cssText).toBe('color: red;') + + setStyle(el, '') + expect(el.style.cssText).toBe('') + }) + }) describe('setAttr', () => { test('should set attribute', () => {