UNPKG

@danielkalen/simplybind

Version:

Magically simple, framework-less one-way/two-way data binding for frontend/backend in ~5kb.

55 lines (40 loc) 1.77 kB
suite "DOMCheckbox", ()-> suiteSetup ()-> if not isBrowser then @skip() test "When attempting to bind a property other than 'checked' of a checkbox element list, only the first element will be used", ()-> origLog = console.warn console.warn = chai.spy() SimplyBind('prop1').of(objectA) .to('newProp').of checkboxFields .and.to('newProp').of [].reverse.call($checkboxFields) objectA.prop1 = 'updated' expect(checkboxA.newProp).to.equal 'updated' expect(checkboxC.newProp).to.equal 'updated' expect(checkboxB.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 checkboxFields $checkboxFields.each ()-> @on 'change', ()-> invokeCount++ objectA.prop4 = 'checkboxA' objectA.prop4 = 'checkboxB' objectA.prop4 = 'checkboxB' expect(invokeCount).to.equal 3 SimplyBind.settings.dispatchEvents = false SimplyBind.defaultOptions.updateEvenIfSame = false restartSandbox() test "Initial checked values should be noted during initial binding", ()-> expect(checkboxA.checked).to.be.false expect(checkboxB.checked).to.be.false expect(checkboxC.checked).to.be.false checkboxB.checked = true checkboxC.checked = true SimplyBind('checked').of(checkboxFields).to (checkedFields)-> expect(checkedFields).to.be.instanceOf Array expect(checkedFields.length).to.equal 2 expect(checkedFields[0]).to.equal 'checkboxB' expect(checkedFields[1]).to.equal 'checkboxC'