@danielkalen/simplybind
Version:
Magically simple, framework-less one-way/two-way data binding for frontend/backend in ~5kb.
51 lines (36 loc) • 1.54 kB
text/coffeescript
suite "DOMRadio", ()->
suiteSetup ()-> if not isBrowser then @skip()
test "When attempting to bind a property other than 'checked' of a radio element list, only the first element will be used", ()->
origLog = console.warn
console.warn = chai.spy()
SimplyBind('prop1').of(objectA)
.to('newProp').of radioFields
.and.to('newProp').of [].reverse.call($radioFields)
objectA.prop1 = 'updated'
expect(radioA.newProp).to.equal 'updated'
expect(radioC.newProp).to.equal 'updated'
expect(radioB.newProp).not.to.be.defined
expect(console.warn).to.have.been.called()
console.warn = origLog
restartSandbox()
test "A change event will be dispatched upon value update if SimplyBind.options.dispatchEvents is on", ()->
invokeCount = 0
SimplyBind.settings.dispatchEvents = true
SimplyBind.defaultOptions.updateEvenIfSame = true
SimplyBind('prop4').of(objectA)
.to('checked').of radioFields
$radioFields.each ()-> @on 'change', ()-> invokeCount++
objectA.prop4 = 'radioA'
objectA.prop4 = 'radioB'
objectA.prop4 = 'radioB'
expect(invokeCount).to.equal 2
SimplyBind.settings.dispatchEvents = false
SimplyBind.defaultOptions.updateEvenIfSame = false
restartSandbox()
test "Initial checked values should be noted during initial binding", ()->
expect(radioA.checked).to.be.false
expect(radioB.checked).to.be.false
expect(radioC.checked).to.be.false
radioB.checked = true
SimplyBind('checked').of(radioFields).to (selectedRadio)->
expect(selectedRadio).to.equal 'radioB'