@danielkalen/simplybind
Version:
Magically simple, framework-less one-way/two-way data binding for frontend/backend in ~5kb.
313 lines (284 loc) • 15.7 kB
text/coffeescript
suite "Method availablity in different stages", ()->
test "Stage 0 (Selection Stage)", ()->
binding = ()-> SimplyBind('1')
binding().once.to).to.throw()
binding().of objectA).not.to.throw()
binding().to 'prop2').to.throw()
binding().and.to 'prop2').to.throw()
binding().set 'value').to.throw()
binding().transform ()->).to.throw()
binding().transformAll ()->).to.throw()
binding().transformSelf ()->).to.throw()
binding().condition ()->).to.throw()
binding().conditionAll ()->).to.throw()
binding().bothWays()).to.throw()
binding().setOption('v', 'a')).to.throw()
binding().stopPolling()).to.throw()
binding().pollEvery(1000).stopPolling()).to.throw()
binding().unBind()).to.throw()
binding().chainTo ()->).to.throw()
binding().updateOn 'a').to.throw()
binding().removeUpdater 'a').to.throw()
binding().updateOn('a').of({}).removeUpdater 'a').to.throw()
binding = ()-> SimplyBind('event:click')
binding().once.to).to.throw()
binding().of objectA).not.to.throw()
binding().to 'prop2').to.throw()
binding().and.to 'prop2').to.throw()
binding().set 'value').to.throw()
binding().transform ()->).to.throw()
binding().transformAll ()->).to.throw()
binding().transformSelf ()->).to.throw()
binding().condition ()->).to.throw()
binding().conditionAll ()->).to.throw()
binding().bothWays()).to.throw()
binding().setOption('v', 'a')).to.throw()
binding().stopPolling()).to.throw()
binding().pollEvery(1000).stopPolling()).to.throw()
binding().unBind()).to.throw()
binding().chainTo ()->).to.throw()
binding().updateOn 'a').to.throw()
binding().removeUpdater 'a').to.throw()
binding().updateOn('a').of({}).removeUpdater 'a').to.throw()
binding = ()-> SimplyBind('1').of(objectA).to 'prop1'
binding().once.to).to.throw()
binding().of objectA).not.to.throw()
binding().to 'prop2').to.throw()
binding().and.to 'prop2').to.throw()
binding().set 'value').to.throw()
binding().transform ()->).to.throw()
binding().transformAll ()->).to.throw()
binding().transformSelf ()->).to.throw()
binding().condition ()->).to.throw()
binding().conditionAll ()->).to.throw()
binding().bothWays()).to.throw()
binding().setOption('v', 'a')).to.throw()
binding().stopPolling()).to.throw()
binding().pollEvery(1000).stopPolling()).to.throw()
binding().unBind()).to.throw()
binding().chainTo ()->).to.throw()
binding().updateOn 'a').to.throw()
binding().removeUpdater 'a').to.throw()
binding().updateOn('a').of({}).removeUpdater 'a').to.throw()
binding = ()-> SimplyBind('1').of(objectA).to('prop:prop1').of(objectB).and.to 'prop2'
binding().once.to).to.throw()
binding().of objectA).not.to.throw()
binding().to 'prop2').to.throw()
binding().and.to 'prop2').to.throw()
binding().set 'value').to.throw()
binding().transform ()->).to.throw()
binding().transformAll ()->).to.throw()
binding().transformSelf ()->).to.throw()
binding().condition ()->).to.throw()
binding().conditionAll ()->).to.throw()
binding().bothWays()).to.throw()
binding().setOption('v', 'a')).to.throw()
binding().stopPolling()).to.throw()
binding().pollEvery(1000).stopPolling()).to.throw()
binding().unBind()).to.throw()
binding().chainTo ()->).to.throw()
binding().updateOn 'a').to.throw()
binding().removeUpdater 'a').to.throw()
binding().updateOn('a').of({}).removeUpdater 'a').to.throw()
test "Stage 1 (Indication Stage)", ()->
binding = ()-> SimplyBind('1').of objectA
binding().once.to).not.to.throw()
binding().of objectA).to.throw()
binding().to 'prop2').not.to.throw()
binding().and.to 'prop2').to.throw()
binding().set 'value').not.to.throw()
binding().transform ()->).to.throw()
binding().transformAll ()->).to.throw()
binding().transformSelf ()->).not.to.throw()
binding().condition ()->).to.throw()
binding().conditionAll ()->).to.throw()
binding().bothWays()).to.throw()
binding().setOption('v', 'a')).to.throw()
binding().stopPolling()).not.to.throw()
binding().pollEvery(1000).stopPolling()).not.to.throw()
binding().unBind()).to.throw()
binding().chainTo ()->).to.throw()
binding().updateOn 'a').not.to.throw()
binding().removeUpdater 'a').to.throw()
binding().updateOn('a').of({}).removeUpdater 'a').not.to.throw()
test "Stage 2 (Binding Complete Stage)", ()->
binding = ()-> SimplyBind('1').of(objectA).to('prop1').of objectB
binding().once.to).to.throw()
binding().of objectA).to.throw()
binding().to 'prop2').to.throw()
binding().and.to 'prop2').not.to.throw()
binding().set 'value').not.to.throw()
binding().transform ()->).not.to.throw()
binding().transformAll ()->).not.to.throw()
binding().transformSelf ()->).to.throw()
binding().condition ()->).not.to.throw()
binding().conditionAll ()->).not.to.throw()
binding().bothWays()).not.to.throw()
binding().setOption('v', 'a')).not.to.throw()
binding().stopPolling()).not.to.throw()
binding().pollEvery(1000).stopPolling()).not.to.throw()
binding().unBind()).not.to.throw()
binding().chainTo ()->).not.to.throw()
binding().updateOn 'a').not.to.throw()
binding().updateOn('a').of(window).removeUpdater 'a').not.to.throw()
binding = ()-> SimplyBind('1').of(objectA).to('prop1').of(objectB).and.to('prop2').of objectB
binding().once.to).to.throw()
binding().of objectA).to.throw()
binding().to 'prop2').to.throw()
binding().and.to 'prop2').not.to.throw()
binding().set 'value').not.to.throw()
binding().transform ()->).not.to.throw()
binding().transformAll ()->).not.to.throw()
binding().transformSelf ()->).to.throw()
binding().condition ()->).not.to.throw()
binding().conditionAll ()->).not.to.throw()
binding().bothWays()).not.to.throw()
binding().setOption('v', 'a')).not.to.throw()
binding().stopPolling()).not.to.throw()
binding().pollEvery(1000).stopPolling()).not.to.throw()
binding().unBind()).not.to.throw()
binding().chainTo ()->).not.to.throw()
binding().updateOn 'a').not.to.throw()
binding().updateOn('a').of(window).removeUpdater 'a').not.to.throw()
binding = ()-> SimplyBind('1').of(objectA).to('prop1').of(objectB).bothWays()
binding().once.to).to.throw()
binding().of objectA).to.throw()
binding().to 'prop2').to.throw()
binding().and.to 'prop2').not.to.throw()
binding().set 'value').not.to.throw()
binding().transform ()->).not.to.throw()
binding().transformAll ()->).not.to.throw()
binding().transformSelf ()->).to.throw()
binding().condition ()->).not.to.throw()
binding().conditionAll ()->).not.to.throw()
binding().bothWays()).not.to.throw()
binding().setOption('v', 'a')).not.to.throw()
binding().stopPolling()).not.to.throw()
binding().pollEvery(1000).stopPolling()).not.to.throw()
binding().unBind()).not.to.throw()
binding().chainTo ()->).not.to.throw()
binding().updateOn 'a').not.to.throw()
binding().updateOn('a').of(window).removeUpdater 'a').not.to.throw()
binding = ()-> SimplyBind('1').of(objectA).to('prop1').of(objectB).transform ()->
binding().once.to).to.throw()
binding().of objectA).to.throw()
binding().to 'prop2').to.throw()
binding().and.to 'prop2').not.to.throw()
binding().set 'value').not.to.throw()
binding().transform ()->).not.to.throw()
binding().transformAll ()->).not.to.throw()
binding().transformSelf ()->).to.throw()
binding().condition ()->).not.to.throw()
binding().conditionAll ()->).not.to.throw()
binding().bothWays()).not.to.throw()
binding().setOption('v', 'a')).not.to.throw()
binding().stopPolling()).not.to.throw()
binding().pollEvery(1000).stopPolling()).not.to.throw()
binding().unBind()).not.to.throw()
binding().chainTo ()->).not.to.throw()
binding().updateOn 'a').not.to.throw()
binding().updateOn('a').of(window).removeUpdater 'a').not.to.throw()
binding = ()-> SimplyBind('1').of(objectA).to('prop1').of(objectB).transformAll ()->
binding().once.to).to.throw()
binding().of objectA).to.throw()
binding().to 'prop2').to.throw()
binding().and.to 'prop2').not.to.throw()
binding().set 'value').not.to.throw()
binding().transform ()->).not.to.throw()
binding().transformAll ()->).not.to.throw()
binding().transformSelf ()->).to.throw()
binding().condition ()->).not.to.throw()
binding().conditionAll ()->).not.to.throw()
binding().bothWays()).not.to.throw()
binding().setOption('v', 'a')).not.to.throw()
binding().stopPolling()).not.to.throw()
binding().pollEvery(1000).stopPolling()).not.to.throw()
binding().unBind()).not.to.throw()
binding().chainTo ()->).not.to.throw()
binding().updateOn 'a').not.to.throw()
binding().updateOn('a').of(window).removeUpdater 'a').not.to.throw()
binding = ()-> SimplyBind('1').of(objectA).to('prop1').of(objectB).condition ()->
binding().once.to).to.throw()
binding().of objectA).to.throw()
binding().to 'prop2').to.throw()
binding().and.to 'prop2').not.to.throw()
binding().set 'value').not.to.throw()
binding().transform ()->).not.to.throw()
binding().transformAll ()->).not.to.throw()
binding().transformSelf ()->).to.throw()
binding().condition ()->).not.to.throw()
binding().conditionAll ()->).not.to.throw()
binding().bothWays()).not.to.throw()
binding().setOption('v', 'a')).not.to.throw()
binding().stopPolling()).not.to.throw()
binding().pollEvery(1000).stopPolling()).not.to.throw()
binding().unBind()).not.to.throw()
binding().chainTo ()->).not.to.throw()
binding().updateOn 'a').not.to.throw()
binding().updateOn('a').of(window).removeUpdater 'a').not.to.throw()
binding = ()-> SimplyBind('1').of(objectA).to('prop1').of(objectB).conditionAll ()->
binding().once.to).to.throw()
binding().of objectA).to.throw()
binding().to 'prop2').to.throw()
binding().and.to 'prop2').not.to.throw()
binding().set 'value').not.to.throw()
binding().transform ()->).not.to.throw()
binding().transformAll ()->).not.to.throw()
binding().transformSelf ()->).to.throw()
binding().condition ()->).not.to.throw()
binding().conditionAll ()->).not.to.throw()
binding().bothWays()).not.to.throw()
binding().setOption('v', 'a')).not.to.throw()
binding().stopPolling()).not.to.throw()
binding().pollEvery(1000).stopPolling()).not.to.throw()
binding().unBind()).not.to.throw()
binding().chainTo ()->).not.to.throw()
binding().updateOn 'a').not.to.throw()
binding().updateOn('a').of(window).removeUpdater 'a').not.to.throw()
binding = ()-> SimplyBind('1').of(objectA).to('prop1').of(objectB).transform(()->).and.to ()->
binding().once.to).to.throw()
binding().of objectA).to.throw()
binding().to 'prop2').to.throw()
binding().and.to 'prop2').not.to.throw()
binding().set 'value').not.to.throw()
binding().transform ()->).not.to.throw()
binding().transformAll ()->).not.to.throw()
binding().transformSelf ()->).to.throw()
binding().condition ()->).not.to.throw()
binding().conditionAll ()->).not.to.throw()
binding().bothWays()).not.to.throw()
binding().setOption('v', 'a')).not.to.throw()
binding().stopPolling()).not.to.throw()
binding().pollEvery(1000).stopPolling()).not.to.throw()
binding().unBind()).not.to.throw()
binding().chainTo ()->).not.to.throw()
binding().updateOn 'a').not.to.throw()
binding().updateOn('a').of(window).removeUpdater 'a').not.to.throw()
binding = ()-> SimplyBind('1').of(objectA).to('prop1').of(objectB).transform(()->).and.to(()->).chainTo ()->
binding().once.to).to.throw()
binding().of objectA).to.throw()
binding().to 'prop2').to.throw()
binding().and.to 'prop2').not.to.throw()
binding().set 'value').not.to.throw()
binding().transform ()->).not.to.throw()
binding().transformAll ()->).not.to.throw()
binding().transformSelf ()->).to.throw()
binding().condition ()->).not.to.throw()
binding().conditionAll ()->).not.to.throw()
binding().bothWays()).not.to.throw()
binding().setOption('v', 'a')).not.to.throw()
binding().stopPolling()).not.to.throw()
binding().pollEvery(1000).stopPolling()).not.to.throw()
binding().unBind()).not.to.throw()
binding().chainTo ()->).not.to.throw()
binding().updateOn 'a').not.to.throw()
binding().updateOn('a').of(window).removeUpdater 'a').not.to.throw()
test "Aliases", ()->
binding = SimplyBind('prop').of(objectA).to('prop').of(objectB)
expect(binding.update).to.equal(binding.set)
expect(binding.twoWay).to.equal(binding.bothWays)
expect(binding.pipe).to.equal(binding.chainTo)
binding.set('value')).not.to.throw()
binding.twoWay()).not.to.throw()
binding.pipe('a')).not.to.throw()
restartSandbox()