style.spec.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import { patch } from 'web/runtime/patch'
  2. import VNode from 'core/vdom/vnode'
  3. describe('vdom style module', () => {
  4. it('should create an element with style', () => {
  5. const vnode = new VNode('p', { style: { fontSize: '12px' }})
  6. const elm = patch(null, vnode)
  7. expect(elm.style.fontSize).toBe('12px')
  8. })
  9. it('should create an element with array style', () => {
  10. const vnode = new VNode('p', { style: [{ fontSize: '12px' }, { color: 'red' }] })
  11. const elm = patch(null, vnode)
  12. expect(elm.style.fontSize).toBe('12px')
  13. expect(elm.style.color).toBe('red')
  14. })
  15. it('should change elements style', () => {
  16. const vnode1 = new VNode('p', { style: { fontSize: '12px' }})
  17. const vnode2 = new VNode('p', { style: { fontSize: '10px', display: 'block' }})
  18. patch(null, vnode1)
  19. const elm = patch(vnode1, vnode2)
  20. expect(elm.style.fontSize).toBe('10px')
  21. expect(elm.style.display).toBe('block')
  22. })
  23. it('should remove elements attrs', () => {
  24. const vnode1 = new VNode('p', { style: { fontSize: '12px' }})
  25. const vnode2 = new VNode('p', { style: { display: 'block' }})
  26. patch(null, vnode1)
  27. const elm = patch(vnode1, vnode2)
  28. expect(elm.style.fontSize).toBe('')
  29. expect(elm.style.display).toBe('block')
  30. })
  31. })