refactor: adjust runtime-dom test structure + tests for dom props

This commit is contained in:
Evan You
2020-04-10 15:37:30 -04:00
parent ed235f16de
commit ab16a065a8
6 changed files with 73 additions and 9 deletions

View File

@@ -0,0 +1,31 @@
import { patchProp } from '../src/patchProp'
import { ElementWithTransition } from '../src/components/Transition'
import { svgNS } from '../src/nodeOps'
describe('runtime-dom: class patching', () => {
test('basics', () => {
const el = document.createElement('div')
patchProp(el, 'class', null, 'foo')
expect(el.className).toBe('foo')
patchProp(el, 'class', null, null)
expect(el.className).toBe('')
})
test('transition class', () => {
const el = document.createElement('div') as ElementWithTransition
el._vtc = new Set(['bar', 'baz'])
patchProp(el, 'class', null, 'foo')
expect(el.className).toBe('foo bar baz')
patchProp(el, 'class', null, null)
expect(el.className).toBe('bar baz')
delete el._vtc
patchProp(el, 'class', null, 'foo')
expect(el.className).toBe('foo')
})
test('svg', () => {
const el = document.createElementNS(svgNS, 'svg')
patchProp(el, 'class', null, 'foo', true)
expect(el.getAttribute('class')).toBe('foo')
})
})