Skip to content

Commit 05b8dbd

Browse files
committed
test: Implement setClassIncremental and setStyleIncremental tests.
1 parent 1706a6f commit 05b8dbd

File tree

1 file changed

+85
-2
lines changed

1 file changed

+85
-2
lines changed

packages/runtime-vapor/__tests__/dom/prop.spec.ts

Lines changed: 85 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,92 @@ describe('patchProp', () => {
188188
})
189189
})
190190

191-
describe.todo('setClassIncremental', () => {})
191+
describe('setClassIncremental', () => {
192+
test('should set class', () => {
193+
const el = document.createElement('div')
194+
// mark as root
195+
;(el as any).$root = true
196+
setClass(el, 'foo')
197+
expect(el.className).toBe('foo')
198+
199+
// Should replace previous class set by setClass
200+
setClass(el, 'bar')
201+
expect(el.className).toBe('bar')
202+
})
203+
204+
test('should coexist with existing classes', () => {
205+
const el = document.createElement('div')
206+
el.className = 'existing'
207+
;(el as any).$root = true
208+
209+
setClass(el, 'foo')
210+
expect(el.className).toBe('existing foo')
211+
212+
setClass(el, 'bar')
213+
expect(el.className).toBe('existing bar')
214+
215+
setClass(el, '')
216+
expect(el.className).toBe('existing')
217+
})
218+
219+
test('should handle multiple classes', () => {
220+
const el = document.createElement('div')
221+
;(el as any).$root = true
222+
223+
setClass(el, 'foo bar')
224+
expect(el.className).toBe('foo bar')
225+
226+
setClass(el, 'baz')
227+
expect(el.className).toBe('baz')
228+
})
229+
})
230+
231+
describe('setStyleIncremental', () => {
232+
test('should set style', () => {
233+
const el = document.createElement('div')
234+
;(el as any).$root = true
235+
setStyle(el, 'color: red')
236+
expect(el.style.cssText).toBe('color: red;')
192237

193-
describe.todo('setStyleIncremental', () => {})
238+
setStyle(el, 'font-size: 12px')
239+
expect(el.style.cssText).toBe('font-size: 12px;')
240+
})
241+
242+
test('should coexist with existing styles', () => {
243+
const el = document.createElement('div')
244+
el.style.display = 'block'
245+
;(el as any).$root = true
246+
247+
setStyle(el, 'color: red')
248+
expect(el.style.display).toBe('block')
249+
expect(el.style.color).toBe('red')
250+
251+
setStyle(el, 'font-size: 12px')
252+
expect(el.style.display).toBe('block')
253+
expect(el.style.fontSize).toBe('12px')
254+
expect(el.style.color).toBe('')
255+
})
256+
257+
test('should set style with object', () => {
258+
const el = document.createElement('div')
259+
;(el as any).$root = true
260+
setStyle(el, { color: 'red' })
261+
expect(el.style.cssText).toBe('color: red;')
262+
263+
setStyle(el, { fontSize: '12px' })
264+
expect(el.style.cssText).toBe('font-size: 12px;')
265+
})
266+
267+
test('should remove style', () => {
268+
const el = document.createElement('div')
269+
;(el as any).$root = true
270+
setStyle(el, 'color: red')
271+
expect(el.style.cssText).toBe('color: red;')
272+
273+
setStyle(el, '')
274+
expect(el.style.cssText).toBe('')
275+
})
276+
})
194277

195278
describe('setAttr', () => {
196279
test('should set attribute', () => {

0 commit comments

Comments
 (0)