UNPKG

@danielkalen/simplybind

Version:

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

1,283 lines (1,279 loc) 220 kB
// Generated by CoffeeScript 1.10.0 var SimplyBind, chai, chaiSpies, expect, isBrowser, restartSandbox, should, startSandbox; if ((typeof mocha !== "undefined" && mocha !== null) && (typeof window !== "undefined" && window !== null)) { isBrowser = true; mocha.setup('tdd'); if (!(this.isSauceLabsTest || location.hostname)) { mocha.bail(); } } else { isBrowser = false; global.window = global; chai = require('chai'); chaiSpies = require('chai-spies'); SimplyBind = require('../dist/simplybind.node.js'); startSandbox = require('./spec-helper.js').startSandbox; restartSandbox = require('./spec-helper.js').restartSandbox; chai.use(chaiSpies); } expect = chai.expect; should = chai.should(); suite("SimplyBind", function() { suiteSetup(startSandbox); suite("Options", function() { test("SimplyBind.options should contain the global options list", function() { var options; options = SimplyBind.options; expect(options.silent).not.to.be.undefined; expect(options.liveProps).not.to.be.undefined; expect(options.dispatchEvents).not.to.be.undefined; expect(options.updateEvenIfSame).not.to.be.undefined; expect(options.updateOnBind).not.to.be.undefined; expect(options.mutateInherited).not.to.be.undefined; expect(options.trackArrayChildren).not.to.be.undefined; expect(options.simpleSelector).not.to.be.undefined; expect(options.promiseTransforms).not.to.be.undefined; return expect(options.placeholder).not.to.be.undefined; }); test("SimplyBind.options should return a non-editable copy of the global options list", function() { expect(SimplyBind.options.dispatchEvents).to.be["false"]; SimplyBind.options.dispatchEvents = true; return expect(SimplyBind.options.dispatchEvents).to.be["false"]; }); test("SimplyBind.setOption() should set a new value for a single option", function() { expect(SimplyBind.options.silent).to.equal(false); SimplyBind.setOption('silent', true); expect(SimplyBind.options.silent).to.equal(true); return SimplyBind.setOption('silent', false); }); test("SimplyBind.setOptions() should set new values for a all the options passed", function() { expect(SimplyBind.options.silent).to.equal(false); expect(SimplyBind.options.liveProps).to.equal(true); SimplyBind.setOptions({ 'silent': true, 'liveProps': false }); expect(SimplyBind.options.silent).to.equal(true); expect(SimplyBind.options.liveProps).to.equal(false); SimplyBind.setOptions({ 'silent': false, 'liveProps': true }); SimplyBind.setOptions({}); expect(SimplyBind.options.silent).to.equal(false); return expect(SimplyBind.options.liveProps).to.equal(true); }); test("SimplyBind.setOptions() should not add non-registered options", function() { SimplyBind.setOptions({ placeholder: ['{{', '}}'], youtube: 'yea!' }); expect(SimplyBind.options.placeholder[0]).to.equal('{{'); expect(SimplyBind.options.placeholder[1]).to.equal('}}'); return expect(SimplyBind.options.youtube).to.be.undefined; }); test("<bound instance>.setOption should update a registered option only for the instance", function() { var binding; SimplyBind.setOption('updateOnBind', false); expect(SimplyBind.options.updateOnBind).to.be["false"]; binding = SimplyBind('prop1').of(objectA); expect(binding._.options.updateOnBind).to.be["false"]; binding.setOption('updateOnBind', true); expect(binding._.options.updateOnBind).to.be["true"]; expect(SimplyBind.options.updateOnBind).to.be["false"]; SimplyBind.setOption('updateOnBind', true); return restartSandbox(); }); test("Creating a new binding interface for a cached binding without passing an options object shouldn't overwrite existing options", function() { var binding; SimplyBind.setOption('updateOnBind', false); expect(SimplyBind.options.updateOnBind).to.be["false"]; binding = SimplyBind('prop1').of(objectA); expect(binding._.options.updateOnBind).to.be["false"]; binding.setOption('updateOnBind', true); expect(SimplyBind('prop1').of(objectA)._.options.updateOnBind).to.be["true"]; expect(SimplyBind.options.updateOnBind).to.be["false"]; SimplyBind.setOption('updateOnBind', true); return restartSandbox(); }); test("<bound instance>.setOption should update a registered option only for the instance", function() { var binding; binding = SimplyBind('prop1').of(objectA); binding.setOption('placeholder', ['{{', '}}']); binding.setOption('youtube', 'yea'); expect(binding._.options.placeholder[0]).to.equal('{{'); expect(binding._.options.placeholder[1]).to.equal('}}'); expect(binding._.options.youtube).to.be.undefined; return restartSandbox(); }); test("Passing an options object as the 2nd param of .of() should update registered options only for the instance", function() { var binding; SimplyBind.setOption('updateOnBind', false); expect(SimplyBind.options.updateOnBind).to.be["false"]; binding = SimplyBind('prop1', { 'updateOnBind': true }).of(objectA); expect(binding._.options.updateOnBind).to.be["true"]; expect(SimplyBind.options.updateOnBind).to.be["false"]; SimplyBind.setOption('updateOnBind', true); return restartSandbox(); }); test("Passing an options object as the 2nd param of .of() should update the options even for an existing binding instance", function() { var binding; SimplyBind.setOption('updateOnBind', false); expect(SimplyBind.options.updateOnBind).to.be["false"]; binding = SimplyBind('prop1').of(objectA); expect(binding._.options.updateOnBind).to.be["false"]; binding = SimplyBind('prop1', { 'updateOnBind': true, 'nonexistent': true }).of(objectA); expect(binding._.options.updateOnBind).to.be["true"]; expect(binding._.options.nonexistent).to.be.undefined; expect(SimplyBind.options.updateOnBind).to.be["false"]; SimplyBind.setOption('updateOnBind', true); return restartSandbox(); }); return test("Passing an options object as the 2nd param of .of() for an existing binding should invoke the required methods for these options", function() { var arrayInvokeCount, bindings, newOptions; SimplyBind.setOption('liveProps', false); SimplyBind.setOption('updateOnBind', false); SimplyBind.setOption('mutateInherited', false); SimplyBind.setOption('trackArrayChildren', false); Object.prototype.id = ''; arrayInvokeCount = 0; newOptions = { 'liveProps': true, 'mutateInherited': true, 'trackArrayChildren': true }; bindings = { 'liveProps': SimplyBind('prop1').of(objectA), 'mutateInherited': SimplyBind('id').of(objectB), 'trackArrayChildren': SimplyBind(arrayA).to(function() { return arrayInvokeCount++; }) }; objectA.prop1 = '1'; expect(bindings.liveProps.value).not.to.equal('1'); objectB.id = '1'; expect(bindings.mutateInherited.value).not.to.equal('1'); arrayA[3] = '1'; expect(arrayInvokeCount).to.equal(0); SimplyBind.setOption('liveProps', true); SimplyBind.setOption('updateOnBind', true); SimplyBind('prop1', newOptions).of(objectA); SimplyBind('id', newOptions).of(objectB); SimplyBind(arrayA, newOptions); objectA.prop1 = '2'; expect(bindings.liveProps.value).to.equal('2'); objectB.id = '2'; expect(bindings.mutateInherited.value).to.equal('2'); arrayA[5] = '2'; expect(arrayInvokeCount).to.equal(1); delete Object.prototype.id; return restartSandbox(); }); }); suite("Argument Values", function() { suiteSetup(restartSandbox); suite("SimplyBind() function", function() { test("Can only accept an object type of String, Number, Array, Function, or an existing binding instance", function() { expect(function() { return SimplyBind('s'); }).not.to["throw"](); expect(function() { return SimplyBind(0); }).not.to["throw"](); expect(function() { return SimplyBind([]); }).not.to["throw"](); expect(function() { return SimplyBind(function() {}); }).not.to["throw"](); expect(function() { return SimplyBind(SimplyBind('prop1').of(objectA)); }).not.to["throw"](); expect(function() { return SimplyBind(true); }).to["throw"](); expect(function() { return SimplyBind(null); }).to["throw"](); expect(function() { return SimplyBind(void 0); }).to["throw"](); expect(function() { return SimplyBind({}); }).to["throw"](); expect(function() { return SimplyBind(new Date()); }).to["throw"](); if (isBrowser) { expect(function() { return SimplyBind($('<div />')[0]); }).to["throw"](); } if (window.Map && window.Set && window.Symbol) { expect(function() { return SimplyBind(new Map()); }).to["throw"](); expect(function() { return SimplyBind(new WeakMap()); }).to["throw"](); expect(function() { return SimplyBind(new Set()); }).to["throw"](); expect(function() { return SimplyBind(new WeakSet()); }).to["throw"](); return expect(function() { return SimplyBind(Symbol('a')); }).to["throw"](); } }); return test("Should throw when passing an empty string", function() { return expect(function() { return SimplyBind(''); }).to["throw"](); }); }); suite(".of() method", function() { test("Can only accept non-primitive objects", function() { expect(function() { return SimplyBind(0).of([]); }).not.to["throw"](); expect(function() { return SimplyBind(0).of(function() {}); }).not.to["throw"](); expect(function() { return SimplyBind(0).of({}); }).not.to["throw"](); expect(function() { return SimplyBind(0).of(new Date()); }).not.to["throw"](); if (isBrowser) { expect(function() { return SimplyBind(0).of($('<div />')[0]); }).not.to["throw"](); } if (window.Map && window.Set && window.Symbol) { expect(function() { return SimplyBind(0).of(new Map()); }).not.to["throw"](); expect(function() { return SimplyBind(0).of(new WeakMap()); }).not.to["throw"](); expect(function() { return SimplyBind(0).of(new Set()); }).not.to["throw"](); expect(function() { return SimplyBind(0).of(new WeakSet()); }).not.to["throw"](); expect(function() { return SimplyBind(0).of(Symbol(0)); }).to["throw"](); } expect(function() { return SimplyBind(0).of(SimplyBind('prop1').of(objectA)); }).not.to["throw"](); expect(function() { return SimplyBind(0).of('s'); }).to["throw"](); expect(function() { return SimplyBind(0).of(0); }).to["throw"](); expect(function() { return SimplyBind(0).of(true); }).to["throw"](); expect(function() { return SimplyBind(0).of(null); }).to["throw"](); return expect(function() { return SimplyBind(0).of(void 0); }).to["throw"](); }); return test("Will extract and use the subject bound object from the instance if passed a binding instance", function() { var bound, bound2; bound = SimplyBind('prop3').of(objectA).to('prop3').of(objectB); bound.set('standard'); expect(objectA.prop3).to.equal('standard'); expect(objectB.prop3).to.equal('standard'); bound2 = SimplyBind('prop4').of(bound).to('prop4').of(objectB); bound2.set('ofBounded'); expect(objectA.prop4).to.equal('ofBounded'); return expect(objectB.prop4).to.equal('ofBounded'); }); }); suite(".ofEvent() method", function() { return test("Can only accept string values", function() { expect(function() { return SimplyBind(0).ofEvent('s'); }).not.to["throw"](); expect(function() { return SimplyBind(0).of(objectA).toEvent('s'); }).not.to["throw"](); expect(function() { return SimplyBind(0).ofEvent([]); }).to["throw"](); expect(function() { return SimplyBind(0).ofEvent(function() {}); }).to["throw"](); expect(function() { return SimplyBind(0).ofEvent({}); }).to["throw"](); expect(function() { return SimplyBind(0).ofEvent(new Date()); }).to["throw"](); if (isBrowser) { expect(function() { return SimplyBind(0).ofEvent($('<div />')[0]); }).to["throw"](); } if (window.Map && window.Set && window.Symbol) { expect(function() { return SimplyBind(0).ofEvent(new Map()); }).to["throw"](); expect(function() { return SimplyBind(0).ofEvent(new WeakMap()); }).to["throw"](); expect(function() { return SimplyBind(0).ofEvent(new Set()); }).to["throw"](); expect(function() { return SimplyBind(0).ofEvent(new WeakSet()); }).to["throw"](); expect(function() { return SimplyBind(0).ofEvent(Symbol(0)); }).to["throw"](); } expect(function() { return SimplyBind(0).ofEvent(SimplyBind(0).ofEvent('s')); }).to["throw"](); expect(function() { return SimplyBind(0).ofEvent(0); }).to["throw"](); expect(function() { return SimplyBind(0).ofEvent(true); }).to["throw"](); expect(function() { return SimplyBind(0).ofEvent(null); }).to["throw"](); return expect(function() { return SimplyBind(0).ofEvent(void 0); }).to["throw"](); }); }); suite(".transform/condition/All/Self() methods", function() { return test("Can only accept function values", function() { var timesCalled; window.origLog = console.warn; console.warn = chai.spy(); timesCalled = 0; SimplyBind(0).of({}).to(function() {}).transform(function() {}); expect(console.warn).to.have.been.called.exactly(timesCalled += 0); SimplyBind(0).of({}).to(function() {}).transformAll(function() {}); expect(console.warn).to.have.been.called.exactly(timesCalled += 0); SimplyBind(0).of({}).to(function() {}).condition(function() {}); expect(console.warn).to.have.been.called.exactly(timesCalled += 0); SimplyBind(0).of({}).to(function() {}).conditionAll(function() {}); expect(console.warn).to.have.been.called.exactly(timesCalled += 0); SimplyBind(0).of({}).transformSelf(function() {}); expect(console.warn).to.have.been.called.exactly(timesCalled += 0); SimplyBind(0).of({}).to(function() {}).transform([]); expect(console.warn).to.have.been.called.exactly(timesCalled += 1); SimplyBind(0).of({}).to(function() {}).transformAll({}); expect(console.warn).to.have.been.called.exactly(timesCalled += 1); SimplyBind(0).of({}).to(function() {}).conditionAll(new Date()); expect(console.warn).to.have.been.called.exactly(timesCalled += 1); if (isBrowser) { SimplyBind(0).of({}).to(function() {}).condition($('<div />')[0]); expect(console.warn).to.have.been.called.exactly(timesCalled += 1); } if (window.Map && window.Set && window.Symbol) { SimplyBind(0).of({}).to(function() {}).transform(new Map()); expect(console.warn).to.have.been.called.exactly(timesCalled += 1); SimplyBind(0).of({}).to(function() {}).transformAll(new WeakMap()); expect(console.warn).to.have.been.called.exactly(timesCalled += 1); SimplyBind(0).of({}).to(function() {}).condition(new Set()); expect(console.warn).to.have.been.called.exactly(timesCalled += 1); SimplyBind(0).of({}).to(function() {}).conditionAll(new WeakSet()); expect(console.warn).to.have.been.called.exactly(timesCalled += 1); SimplyBind(0).of({}).transformSelf(Symbol(0)); expect(console.warn).to.have.been.called.exactly(timesCalled += 1); } SimplyBind(0).of({}).to(function() {}).transform(SimplyBind('prop1').of(objectA)); expect(console.warn).to.have.been.called.exactly(timesCalled += 1); SimplyBind(0).of({}).to(function() {}).transformAll('s'); expect(console.warn).to.have.been.called.exactly(timesCalled += 1); SimplyBind(0).of({}).to(function() {}).condition(0); expect(console.warn).to.have.been.called.exactly(timesCalled += 1); SimplyBind(0).of({}).to(function() {}).conditionAll(true); expect(console.warn).to.have.been.called.exactly(timesCalled += 1); SimplyBind(0).of({}).transformSelf(null); expect(console.warn).to.have.been.called.exactly(timesCalled += 1); SimplyBind(0).of({}).transformSelf(void 0); expect(console.warn).to.have.been.called.exactly(timesCalled += 1); return console.warn = origLog; }); }); return suite(".throttle()", function() { return test("Will only accept a truthy number-type argument or a boolean false", function() { var binding; binding = SimplyBind('prop').of(objectA)._; expect(binding.throttleRate || binding.thR).to.be.undefined; SimplyBind('prop').of(objectA).throttle(200); expect(binding.throttleRate || binding.thR).to.equal(200); SimplyBind('prop').of(objectA).throttle(false); expect(binding.throttleRate || binding.thR).to.equal.undefined; SimplyBind('prop').of(objectA).throttle(0); expect(binding.throttleRate || binding.thR).to.equal.undefined; SimplyBind('prop').of(objectA).throttle('0'); expect(binding.throttleRate || binding.thR).to.equal.undefined; SimplyBind('prop').of(objectA).throttle(NaN); expect(binding.throttleRate || binding.thR).to.equal.undefined; SimplyBind('prop').of(objectA).throttle({}); expect(binding.throttleRate || binding.thR).to.equal.undefined; SimplyBind('prop').of(objectA).throttle([]); expect(binding.throttleRate || binding.thR).to.equal.undefined; SimplyBind('prop').of(objectA).throttle(function() {}); expect(binding.throttleRate || binding.thR).to.equal.undefined; if (window.Map && window.Set && window.Symbol) { SimplyBind('prop').of(objectA).throttle(new Map()); expect(binding.throttleRate || binding.thR).to.equal.undefined; SimplyBind('prop').of(objectA).throttle(new WeakMap()); expect(binding.throttleRate || binding.thR).to.equal.undefined; SimplyBind('prop').of(objectA).throttle(new Set()); expect(binding.throttleRate || binding.thR).to.equal.undefined; SimplyBind('prop').of(objectA).throttle(new WeakSet()); expect(binding.throttleRate || binding.thR).to.equal.undefined; SimplyBind('prop').of(objectA).throttle(Symbol(9)); expect(binding.throttleRate || binding.thR).to.equal.undefined; } return restartSandbox(); }); }); }); suite("Errors & Warnings", function() { suiteSetup(restartSandbox); test("Warning when binding a property of a jQuery element containing multiple els", function() { if (!isBrowser) { return this.skip(); } else { window.origLog = console.warn; console.warn = chai.spy(); SimplyBind('value').of($('input')); expect(console.warn).to.have.been.called(); return console.warn = origLog; } }); test("Warning when binding a property of a jQuery element containing zero els", function() { var origLog; if (!isBrowser) { return this.skip(); } else { origLog = console.warn; console.warn = chai.spy(); SimplyBind('value').of($('input[type="nonexistent"]')); expect(console.warn).to.have.been.called(); return console.warn = origLog; } }); test("Warning when binding a property of a NodeList/HTMLCollection containing multiple els", function() { var origLog; if (!isBrowser) { return this.skip(); } else { origLog = console.warn; console.warn = chai.spy(); SimplyBind('value').of(document.querySelectorAll('input')); expect(console.warn).to.have.been.called(); return console.warn = origLog; } }); test("No Warning when binding 'checked' of a jQuery element containing multiple radio/checkbox inputs", function() { var origLog; if (!isBrowser) { return this.skip(); } else { origLog = console.warn; console.warn = chai.spy(); SimplyBind('checked').of($radioFields); expect(console.warn).not.to.have.been.called(); SimplyBind('value').of($radioFields); expect(console.warn).to.have.been.called.exactly(1); return console.warn = origLog; } }); test("No Warning when binding 'checked' of a NodeList/HTMLCollection/Array containing multiple radio/checkbox inputs", function() { var origLog; if (!isBrowser) { return this.skip(); } else { origLog = console.warn; console.warn = chai.spy(); SimplyBind('checked').of($radioFields.toArray()); expect(console.warn).not.to.have.been.called(); SimplyBind('checked').of(radioFields); expect(console.warn).not.to.have.been.called(); SimplyBind('value').of($radioFields.toArray()); SimplyBind('value').of(radioFields); expect(console.warn).to.have.been.called.exactly(2); return console.warn = origLog; } }); test("Warning when binding a property of a NodeList/HTMLCollection/Array/jQuery containing elements with mixed types", function() { var origLog; if (!isBrowser) { return this.skip(); } else { origLog = console.warn; console.warn = chai.spy(); SimplyBind('checked').of($radioFields.add($checkboxFields).toArray()); expect(console.warn).to.have.been.called.exactly(1); SimplyBind('checked').of($radioFields.add($checkboxFields)); expect(console.warn).to.have.been.called.exactly(2); SimplyBind('checked').of(document.querySelectorAll('input')); expect(console.warn).to.have.been.called.exactly(3); return console.warn = origLog; } }); test("Warning when creating a binding and passing a non-function object to .transform/.condition/All", function() { var binding, origLog, timesCalled; binding = SimplyBind('prop1').of(objectA).to('prop1').of(objectB); origLog = console.warn; console.warn = chai.spy(); timesCalled = 0; binding.transform([]); expect(console.warn).to.have.been.called.exactly(timesCalled += 1); binding.transformAll([]); expect(console.warn).to.have.been.called.exactly(timesCalled += 1); binding.transform({}); expect(console.warn).to.have.been.called.exactly(timesCalled += 1); binding.transform(new Date()); expect(console.warn).to.have.been.called.exactly(timesCalled += 1); if (isBrowser) { binding.transform($('<div />')[0]); expect(console.warn).to.have.been.called.exactly(timesCalled += 1); } if (window.Map && window.Set && window.Symbol) { binding.transform(new Map()); expect(console.warn).to.have.been.called.exactly(timesCalled += 1); binding.transform(new WeakMap()); expect(console.warn).to.have.been.called.exactly(timesCalled += 1); binding.transform(new Set()); expect(console.warn).to.have.been.called.exactly(timesCalled += 1); binding.transform(new WeakSet()); expect(console.warn).to.have.been.called.exactly(timesCalled += 1); binding.transform(Symbol(0)); expect(console.warn).to.have.been.called.exactly(timesCalled += 1); } binding.transform('s'); expect(console.warn).to.have.been.called.exactly(timesCalled += 1); binding.transform(0); expect(console.warn).to.have.been.called.exactly(timesCalled += 1); binding.transform(true); expect(console.warn).to.have.been.called.exactly(timesCalled += 1); binding.transform(null); expect(console.warn).to.have.been.called.exactly(timesCalled += 1); binding.transform(void 0); expect(console.warn).to.have.been.called.exactly(timesCalled += 1); binding.condition([]); expect(console.warn).to.have.been.called.exactly(timesCalled += 1); binding.conditionAll([]); expect(console.warn).to.have.been.called.exactly(timesCalled += 1); console.warn = origLog; return restartSandbox(); }); test("Warning when passed a non-number argument selector to an event binding", function() { var origLog; origLog = console.warn; console.warn = chai.spy(); SimplyBind('value').ofEvent('someEvent'); SimplyBind('15').ofEvent('someEvent'); SimplyBind(' 1aos95').ofEvent('someEvent'); expect(console.warn).to.have.been.called.exactly(1); return console.warn = origLog; }); test("No warnings should be thrown when SimplyBind.options.silent is on", function() { var origLog; SimplyBind.setOption('silent', true); origLog = console.warn; console.warn = chai.spy(); SimplyBind('value').ofEvent('someEvent'); SimplyBind('prop3').of(objectA).to('prop3').of(objectB).transform([]); expect(console.warn).not.to.have.been.called(); console.warn = origLog; return SimplyBind.setOption('silent', false); }); test("Errors should still be thrown when SimplyBind.options.silent is on", function() { SimplyBind.setOption('silent', true); expect(function() { return SimplyBind(''); }).to["throw"](); return SimplyBind.setOption('silent', false); }); return test("No errors should be thrown when scanning for placeholders on a non-string object", function() { var dispatcher, receiver; dispatcher = { 'prop': 'value' }; receiver = { 'prop': null }; expect(function() { return SimplyBind('prop').of(dispatcher).to('prop.placeholder').of(receiver); }).not.to["throw"](); return expect(receiver.prop).not.to.equal('value'); }); }); suite("Internal Behavior", function() { suiteSetup(restartSandbox); test("A binding should have the correct public properies available", function() { var binding; binding = SimplyBind('prop1').of(objectA).to('prop2').of(objectB); expect(binding.ID).not.to.be.undefined; expect(binding.value).not.to.be.undefined; expect(binding.original).not.to.be.undefined; expect(binding.dependents).not.to.be.undefined; expect(binding._).not.to.be.undefined; return restartSandbox(); }); test("Bindings to a nonexistent object prop should not create instantiate the object prop at first", function() { var binding; expect(objectA.prop20).to.be.undefined; expect(objectB.prop20).to.be.undefined; binding = SimplyBind('prop20').of(objectA).to('prop20').of(objectB); expect(objectA.prop20).to.be.undefined; expect(objectB.prop20).to.be.undefined; binding.set('new value'); expect(objectA.prop20).to.equal('new value'); expect(objectB.prop20).to.equal('new value'); return restartSandbox(); }); test("The binding.value property and binding.get() method should return the same value", function() { var bound, tempObject; tempObject = { 'a': 'with', 'b': 'text {{verb}} a placeholder' }; SimplyBind('a').of(tempObject).to('b.verb').of(tempObject); bound = SimplyBind('b.verb').of(tempObject); expect(tempObject.b).to.equal('text with a placeholder'); expect(bound.value).to.equal('text with a placeholder'); expect(bound.get()).to.equal('with'); tempObject.a = 'without'; expect(tempObject.b).to.equal('text without a placeholder'); expect(bound.value).to.equal('text without a placeholder'); return expect(bound.get()).to.equal('without'); }); suite("Method availablity in different stages", function() { test("Stage 0 (Selection Stage)", function() { var binding; binding = function() { return SimplyBind('1'); }; expect(function() { return binding().of(objectA); }).not.to["throw"](); expect(function() { return binding().ofEvent(objectA); }).to["throw"](); expect(function() { return binding().to('prop2'); }).to["throw"](); expect(function() { return binding().toEvent('/local'); }).to["throw"](); expect(function() { return binding().and('prop2'); }).to["throw"](); expect(function() { return binding().set('value'); }).to["throw"](); expect(function() { return binding().get(); }).to["throw"](); expect(function() { return binding().transform(function() {}); }).to["throw"](); expect(function() { return binding().transformAll(function() {}); }).to["throw"](); expect(function() { return binding().transformSelf(function() {}); }).to["throw"](); expect(function() { return binding().condition(function() {}); }).to["throw"](); expect(function() { return binding().conditionAll(function() {}); }).to["throw"](); expect(function() { return binding().bothWays(); }).to["throw"](); expect(function() { return binding().stopPolling(); }).to["throw"](); expect(function() { return binding().pollEvery(1000).stopPolling(); }).to["throw"](); expect(function() { return binding().unBind(); }).to["throw"](); expect(function() { return binding().chainTo(function() {}); }).to["throw"](); expect(function() { return binding().updateDepsOnEvent('a'); }).to["throw"](); expect(function() { return binding().removeEvent('a'); }).to["throw"](); expect(function() { return binding().throttle(5); }).to["throw"](); binding = function() { return SimplyBind('1').ofEvent('click'); }; expect(function() { return binding().of(objectA); }).not.to["throw"](); expect(function() { return binding().ofEvent(objectA); }).to["throw"](); expect(function() { return binding().to('prop2'); }).to["throw"](); expect(function() { return binding().toEvent('/local'); }).to["throw"](); expect(function() { return binding().and('prop2'); }).to["throw"](); expect(function() { return binding().set('value'); }).to["throw"](); expect(function() { return binding().get(); }).to["throw"](); expect(function() { return binding().transform(function() {}); }).to["throw"](); expect(function() { return binding().transformAll(function() {}); }).to["throw"](); expect(function() { return binding().transformSelf(function() {}); }).to["throw"](); expect(function() { return binding().condition(function() {}); }).to["throw"](); expect(function() { return binding().conditionAll(function() {}); }).to["throw"](); expect(function() { return binding().bothWays(); }).to["throw"](); expect(function() { return binding().stopPolling(); }).to["throw"](); expect(function() { return binding().pollEvery(1000).stopPolling(); }).to["throw"](); expect(function() { return binding().unBind(); }).to["throw"](); expect(function() { return binding().chainTo(function() {}); }).to["throw"](); expect(function() { return binding().updateDepsOnEvent('a'); }).to["throw"](); expect(function() { return binding().removeEvent('a'); }).to["throw"](); return expect(function() { return binding().throttle(5); }).to["throw"](); }); test("Stage 1 (Indication Stage)", function() { var binding; binding = function() { return SimplyBind('1').of(objectA); }; expect(function() { return binding().of(objectA); }).to["throw"](); expect(function() { return binding().ofEvent(objectA); }).to["throw"](); expect(function() { return binding().to('prop2'); }).not.to["throw"](); expect(function() { return binding().toEvent('/local'); }).not.to["throw"](); expect(function() { return binding().and('prop2'); }).to["throw"](); expect(function() { return binding().set('value'); }).not.to["throw"](); expect(function() { return binding().get(); }).not.to["throw"](); expect(function() { return binding().transform(function() {}); }).to["throw"](); expect(function() { return binding().transformAll(function() {}); }).to["throw"](); expect(function() { return binding().transformSelf(function() {}); }).not.to["throw"](); expect(function() { return binding().condition(function() {}); }).to["throw"](); expect(function() { return binding().conditionAll(function() {}); }).to["throw"](); expect(function() { return binding().bothWays(); }).to["throw"](); expect(function() { return binding().stopPolling(); }).to["throw"](); expect(function() { return binding().pollEvery(1000).stopPolling(); }).to["throw"](); expect(function() { return binding().unBind(); }).to["throw"](); expect(function() { return binding().chainTo(function() {}); }).to["throw"](); expect(function() { return binding().updateDepsOnEvent('a'); }).to["throw"](); expect(function() { return binding().removeEvent('a'); }).to["throw"](); expect(function() { return binding().throttle(5); }).not.to["throw"](); binding = function() { return SimplyBind('1').ofEvent('click').of(eventEmitterA); }; expect(function() { return binding().of(objectA); }).to["throw"](); expect(function() { return binding().ofEvent(objectA); }).to["throw"](); expect(function() { return binding().to('prop2'); }).not.to["throw"](); expect(function() { return binding().toEvent('/local'); }).not.to["throw"](); expect(function() { return binding().and('prop2'); }).to["throw"](); expect(function() { return binding().set('value'); }).not.to["throw"](); expect(function() { return binding().get(); }).not.to["throw"](); expect(function() { return binding().transform(function() {}); }).to["throw"](); expect(function() { return binding().transformAll(function() {}); }).to["throw"](); expect(function() { return binding().transformSelf(function() {}); }).not.to["throw"](); expect(function() { return binding().condition(function() {}); }).to["throw"](); expect(function() { return binding().conditionAll(function() {}); }).to["throw"](); expect(function() { return binding().bothWays(); }).to["throw"](); expect(function() { return binding().stopPolling(); }).to["throw"](); expect(function() { return binding().pollEvery(1000).stopPolling(); }).to["throw"](); expect(function() { return binding().unBind(); }).to["throw"](); expect(function() { return binding().chainTo(function() {}); }).to["throw"](); expect(function() { return binding().updateDepsOnEvent('a'); }).to["throw"](); expect(function() { return binding().removeEvent('a'); }).to["throw"](); return expect(function() { return binding().throttle(5); }).not.to["throw"](); }); test("Stage 2 (Binding Selection Stage)", function() { var binding; binding = function() { return SimplyBind('1').of(objectA).to('prop1'); }; expect(function() { return binding().of(objectA); }).not.to["throw"](); expect(function() { return binding().ofEvent(objectA); }).to["throw"](); expect(function() { return binding().to('prop2'); }).to["throw"](); expect(function() { return binding().toEvent('/local'); }).to["throw"](); expect(function() { return binding().and('prop2'); }).to["throw"](); expect(function() { return binding().set('value'); }).to["throw"](); expect(function() { return binding().get(); }).to["throw"](); expect(function() { return binding().transform(function() {}); }).to["throw"](); expect(function() { return binding().transformAll(function() {}); }).to["throw"](); expect(function() { return binding().transformSelf(function() {}); }).to["throw"](); expect(function() { return binding().condition(function() {}); }).to["throw"](); expect(function() { return binding().conditionAll(function() {}); }).to["throw"](); expect(function() { return binding().bothWays(); }).to["throw"](); expect(function() { return binding().stopPolling(); }).to["throw"](); expect(function() { return binding().pollEvery(1000).stopPolling(); }).to["throw"](); expect(function() { return binding().unBind(); }).to["throw"](); expect(function() { return binding().chainTo(function() {}); }).to["throw"](); expect(function() { return binding().updateDepsOnEvent('a'); }).to["throw"](); expect(function() { return binding().removeEvent('a'); }).to["throw"](); expect(function() { return binding().throttle(5); }).to["throw"](); binding = function() { return SimplyBind('1').of(objectA).to('prop:prop1').of(objectB).and('prop2'); }; expect(function() { return binding().of(objectA); }).not.to["throw"](); expect(function() { return binding().ofEvent(objectA); }).to["throw"](); expect(function() { return binding().to('prop2'); }).to["throw"](); expect(function() { return binding().toEvent('/local'); }).to["throw"](); expect(function() { return binding().and('prop2'); }).to["throw"](); expect(function() { return binding().set('value'); }).to["throw"](); expect(function() { return binding().get(); }).to["throw"](); expect(function() { return binding().transform(function() {}); }).to["throw"](); expect(function() { return binding().transformAll(function() {}); }).to["throw"](); expect(function() { return binding().transformSelf(function() {}); }).to["throw"](); expect(function() { return binding().condition(function() {}); }).to["throw"](); expect(function() { return binding().conditionAll(function() {}); }).to["throw"](); expect(function() { return binding().bothWays(); }).to["throw"](); expect(function() { return binding().stopPolling(); }).to["throw"](); expect(function() { return binding().pollEvery(1000).stopPolling(); }).to["throw"](); expect(function() { return binding().unBind(); }).to["throw"](); expect(function() { return binding().chainTo(function() {}); }).to["throw"](); expect(function() { return binding().updateDepsOnEvent('a'); }).to["throw"](); expect(function() { return binding().removeEvent('a'); }).to["throw"](); return expect(function() { return binding().throttle(5); }).to["throw"](); }); return test("Stage 3 (Binding Complete Stage)", function() { var binding; binding = function() { return SimplyBind('1').of(objectA).to('prop1').of(objectB); }; expect(function() { return binding().of(objectA); }).to["throw"](); expect(function() { return binding().ofEvent(objectA); }).to["throw"](); expect(function() { return binding().to('prop2'); }).to["throw"](); expect(function() { return binding().toEvent('/local'); }).to["throw"](); expect(function() { return binding().and('prop2'); }).not.to["throw"](); expect(function() { return binding().set('value'); }).not.to["throw"](); expect(function() { return binding().get(); }).not.to["throw"](); expect(function() { return binding().transform(function() {}); }).not.to["throw"](); expect(function() { return binding().transformAll(function() {}); }).not.to["throw"](); expect(function() { return binding().transformSelf(function() {}); }).to["throw"](); expect(function() { return binding().condition(function() {}); }).not.to["throw"](); expect(function() { return binding().conditionAll(function() {}); }).not.to["throw"](); expect(function() { return binding().bothWays(); }).not.to["throw"](); expect(function() { return binding().stopPolling(); }).not.to["throw"](); expect(function() { return binding().pollEvery(1000).stopPolling(); }).not.to["throw"](); expect(function() { return binding().unBind(); }).not.to["throw"](); expect(function() { return binding().chainTo(function() {}); }).not.to["throw"](); expect(function() { return binding().updateDepsOnEvent('a'); }).not.to["throw"](); expect(function() { return binding().removeEvent('a'); }).not.to["throw"](); expect(function() { return binding().throttle(5); }).not.to["throw"](); binding = function() { return SimplyBind('1').of(objectA).to('prop1').of(objectB).and('prop2').of(objectB); }; expect(function() { return binding().of(objectA); }).to["throw"](); expect(function() { return binding().ofEvent(objectA); }).to["throw"](); expect(function() { return binding().to('prop2'); }).to["throw"](); expect(function() { return binding().toEvent('/local'); }).to["throw"](); expect(function() { return binding().and('prop2'); }).not.to["throw"](); expect(function() { return binding().set('value'); }).not.to["throw"](); expect(function() { return binding().get(); }).not.to["throw"](); expect(function() { return binding().transform(function() {}); }).not.to["throw"](); expect(function() { return binding().transformAll(function() {}); }).not.to["throw"](); expect(function() { return binding().transformSelf(function() {}); }).to["throw"](); expect(function() { return binding().condition(function() {}); }).not.to["throw"](); expect(function() { return binding().conditionAll(function() {}); }).not.to["throw"](); expect(function() { return binding().bothWays(); }).not.to["throw"](); expect(function() { return binding().stopPolling(); }).not.to["throw"](); expect(function() { return binding().pollEvery(1000).stopPolling(); }).not.to["throw"](); expect(function() { return binding().unBind(); }).not.to["throw"](); expect(function() { return binding().chainTo(function() {}); }).not.to["throw"](); expect(function() { return binding().updateDepsOnEvent('a'); }).not.to["throw"](); expect(function() { return binding().removeEvent('a'); }).not.to["throw"](); expect(function() { return binding().throttle(5); }).not.to["throw"](); binding = function() { return SimplyBind('1').of(objectA).to('prop1').of(objectB).bothWays(); }; expect(function() { return binding().of(objectA); }).to["throw"](); expect(function() { return binding().ofEvent(objectA); }).to["throw"](); expect(function() { return binding().to('prop2'); }).to["throw"](); expect(function() { return binding().toEvent('/local'); }).to["throw"](); expect(function() { return binding().and('prop2'); }).not.to["throw"](); expect(function() { return binding().set('value'); }).not.to["throw"](); expect(function() { return binding().get(); }).not.to["throw"](); expect(function() { return binding().transform(function() {}); }).not.to["throw"](); expect(function() { return binding().transformAll(function() {}); }).not.to["throw"](); expect(function() { return binding().transformSelf(function() {}); }).to["throw"](); expect(function() { return binding().condition(function() {}); }).not.to["throw"](); expect(function() { return binding().conditionAll(function() {}); }).not.to["throw"](); expect(function() { return binding().bothWays(); }).not.to["throw"](); expect(function() { return binding().stopPolling(); }).not.to["throw"](); expect(function() { return binding().pollEvery(1000).stopPolling(); }).not.to["throw"](); expect(function() { return binding().unBind(); }).not.to["throw"](); expect(function() { return binding().chainTo(function() {}); }).not.to["throw"](); expect(function() { return binding().updateDepsOnEvent('a'); }).not.to["throw"](); expect(function() { return binding().removeEvent('a'); }).not.to["throw"](); expect(function() { return binding().throttle(5); }).not.to["throw"](); binding = function() { return SimplyBind('1').of(objectA).to('prop1').of(objectB).transform(function() {}); }; expect(function() { return binding().of(objectA); }).to["throw"](); expect(function() { return binding().ofEvent(objectA); }).to["throw"](); expect(function() { return binding().to('prop2'); }).to["throw"](); expect(function() { return binding().toEvent('/local'); }).to["throw"](); expect(function() { return binding().and('prop2'); }).not.to["throw"](); expect(function() { return binding().set('value'); }).not.to["throw"](); expect(function() { return binding().get(); }).not.to["throw"](); expect(function() { return binding().transform(function() {}); }).to["throw"](); expect(function() { return binding().transformAll(function() {}); }).to["throw"](); expect(function() {