moy-dom
Version:
A flexiable Virtual DOM library for building modern web interface.
88 lines (67 loc) • 1.64 kB
JavaScript
import setProps from '../../src/patch/setProps'
let node
beforeEach(() => {
node = document.createElement('input')
})
describe('test setProps', () => {
describe('normal attributes', () => {
test('normal value', () => {
setProps(node, {
class: 'input',
})
expect(node.className).toBe('input')
expect(node.getAttribute('class')).toBe('input')
})
test('undefined', () => {
setProps(node, {
class: undefined,
})
expect(node.className).toBe('')
expect(node.getAttribute('class')).toBeNull()
})
})
describe('dom events', () => {
test('function', () => {
setProps(node, {
onclick: jest.fn()
})
expect(node.onclick).toEqual(expect.any(Function))
})
test('undefined', () => {
setProps(node, {
onclick: null,
})
expect(node.onclick).toBeNull()
})
})
describe('dom attributes', () => {
test('normal value', () => {
setProps(node, {
value: 'text'
})
expect(node.value).toBe('text')
})
test('undefined', () => {
setProps(node, {
value: undefined
})
expect(node.value).toBe('')
})
})
describe('bool attributes', () => {
test('true', () => {
setProps(node, {
disabled: true,
})
expect(node.disabled).toBeTruthy()
expect(node.getAttribute('disabled')).toEqual('disabled')
})
test('false', () => {
setProps(node, {
disabled: false,
})
expect(node.disabled).toBeFalsy()
expect(node.getAttribute('disabled')).toBeNull()
})
})
})