@danielkalen/simplybind
Version:
Magically simple, framework-less one-way/two-way data binding for frontend/backend in ~5kb.
50 lines (35 loc) • 1.51 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", ()->
sinon.stub(console, 'warn')
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).to.be.undefined
expect(console.warn.called).to.be.true
console.warn.restore()
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'