UNPKG

@danielkalen/simplybind

Version:

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

1,295 lines (1,291 loc) 229 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("Settings/Binding-Options", function() { test("SimplyBind.settings should contain the global settings list", function() { var settings; settings = SimplyBind.settings; expect(settings.silent).not.to.be.undefined; expect(settings.placeholder).not.to.be.undefined; return expect(settings.trackArrayChildren).not.to.be.undefined; }); test("SimplyBind.defaultOptions should contain the default binding options list", function() { var options; options = SimplyBind.defaultOptions; expect(options.dispatchEvents).not.to.be.undefined; expect(options.updateEvenIfSame).not.to.be.undefined; expect(options.updateOnBind).not.to.be.undefined; expect(options.simpleSelector).not.to.be.undefined; return expect(options.promiseTransforms).not.to.be.undefined; }); test("SimplyBind.settings.placeholder should only accept arrays with lengths of 2 as a new value", function() { expect(SimplyBind.settings.placeholder).to.eql(['{{', '}}']); SimplyBind.settings.placeholder = 'na'; expect(SimplyBind.settings.placeholder).to.eql(['{{', '}}']); SimplyBind.settings.placeholder = void 0; expect(SimplyBind.settings.placeholder).to.eql(['{{', '}}']); SimplyBind.settings.placeholder = null; expect(SimplyBind.settings.placeholder).to.eql(['{{', '}}']); SimplyBind.settings.placeholder = function() {}; expect(SimplyBind.settings.placeholder).to.eql(['{{', '}}']); SimplyBind.settings.placeholder = []; expect(SimplyBind.settings.placeholder).to.eql(['{{', '}}']); SimplyBind.settings.placeholder = ['{{', '{{', '}}']; expect(SimplyBind.settings.placeholder).to.eql(['{{', '}}']); SimplyBind.settings.placeholder = ['[[', ']]']; expect(SimplyBind.settings.placeholder).to.eql(['[[', ']]']); SimplyBind.settings.placeholder = ['{{', '}}']; return expect(SimplyBind.settings.placeholder).to.eql(['{{', '}}']); }); test("A custom binding options object can be passed as SimplyBind's second argument to be used for all subscribers added to that publisher interface", function() { var dispatcher, receiver; expect(SimplyBind.defaultOptions.updateOnBind).to.be["true"]; dispatcher = { value: 'uniqueValue' }; receiver = { 1: 1, 2: 2, 3: 3, 4: 4 }; SimplyBind('value', { updateOnBind: false }).of(dispatcher).to('1').of(receiver).and.to('2').of(receiver).and.to('3').of(receiver); expect(receiver[1]).not.to.equal('uniqueValue'); expect(receiver[2]).not.to.equal('uniqueValue'); expect(receiver[3]).not.to.equal('uniqueValue'); SimplyBind('value').of(dispatcher).to('4').of(receiver); expect(receiver[4]).to.equal('uniqueValue'); expect(SimplyBind.defaultOptions.updateOnBind).to.be["true"]; return restartSandbox(); }); test("A truthy value can be passed as SimplyBind's third argument to save the specified options to all subscribers and future subscribers of a publisher", function() { var dispatcher, receiver; expect(SimplyBind.defaultOptions.updateOnBind).to.be["true"]; dispatcher = { value: 'uniqueValue' }; receiver = { 1: 1, 2: 2, 3: 3, 4: 4 }; SimplyBind('value', { updateOnBind: false }, true).of(dispatcher).to('1').of(receiver).and.to('2').of(receiver).and.to('3').of(receiver); expect(receiver[1]).not.to.equal('uniqueValue'); expect(receiver[2]).not.to.equal('uniqueValue'); expect(receiver[3]).not.to.equal('uniqueValue'); SimplyBind('value').of(dispatcher).to('4').of(receiver); expect(receiver[4]).not.to.equal('uniqueValue'); expect(SimplyBind.defaultOptions.updateOnBind).to.be["true"]; return restartSandbox(); }); test("A custom binding options object can be used even for a cached binding/publisher", function() { var dispatcher, receiver; expect(SimplyBind.defaultOptions.updateOnBind).to.be["true"]; dispatcher = { value: 'uniqueValue' }; receiver = { 1: 1, 2: 2, 3: 3, 4: 4 }; SimplyBind('value', { updateOnBind: false }, true).of(dispatcher).to('1').of(receiver).and.to('2').of(receiver).and.to('3').of(receiver); expect(receiver[1]).not.to.equal('uniqueValue'); expect(receiver[2]).not.to.equal('uniqueValue'); expect(receiver[3]).not.to.equal('uniqueValue'); SimplyBind('value', { updateOnBind: true }).of(dispatcher).to('4').of(receiver); expect(receiver[4]).to.equal('uniqueValue'); expect(SimplyBind.defaultOptions.updateOnBind).to.be["true"]; return restartSandbox(); }); return test("Creating a new binding interface for a cached binding without passing an options object shouldn't overwrite existing options", function() { var dispatcher, receiver; expect(SimplyBind.defaultOptions.updateOnBind).to.be["true"]; dispatcher = { value: 'uniqueValue' }; receiver = { 1: 1, 2: 2, 3: 3, 4: 4 }; SimplyBind('value', { updateOnBind: false }, true).of(dispatcher).to('1').of(receiver).and.to('2').of(receiver).and.to('3').of(receiver); expect(receiver[1]).not.to.equal('uniqueValue'); expect(receiver[2]).not.to.equal('uniqueValue'); expect(receiver[3]).not.to.equal('uniqueValue'); SimplyBind('value', null, true).of(dispatcher).to('4').of(receiver); expect(receiver[4]).not.to.equal('uniqueValue'); expect(SimplyBind.defaultOptions.updateOnBind).to.be["true"]; 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 object 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/NodeList/HTMLCollection object containing zero els", function() { if (!isBrowser) { return this.skip(); } else { expect(function() { return SimplyBind('value').of($('nonexistent')); }).to["throw"](); expect(function() { return SimplyBind('value').of(document.querySelectorAll('nonexistent')); }).to["throw"](); return expect(function() { return SimplyBind('value').of(document.getElementsByTagName('nonexistent')); }).to["throw"](); } }); test("Warning when binding a property of a jQuery object containing zero els", function() { if (!isBrowser) { return this.skip(); } else { return expect(function() { return SimplyBind('value').of($('input[type="nonexistent"]')); }).to["throw"](); } }); 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 object 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.settings.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.settings.silent = false; }); test("Errors should still be thrown when SimplyBind.options.silent is on", function() { SimplyBind.settings.silent = true; expect(function() { return SimplyBind(''); }).to["throw"](); return SimplyBind.settings.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.value).not.to.be.undefined; expect(binding.original).not.to.be.undefined; expect(binding.subscribers).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.to('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().updateSubsOnEvent('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.to('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().updateSubsOnEvent('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('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.to('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().updateSubsOnEvent('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.to('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.to('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().updateSubsOnEvent('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.to('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().updateSubsOnEvent('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.to('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().updateSubsOnEvent('a'); }).to["throw"](); expect(function() { return binding().removeEvent('a'); }).to["throw"](); return expect(function() { return binding().throttle(5); }).not.to["throw"](); }); return test("Stage 2 (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.to('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().updateSubsOnEvent('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.to('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.to('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().updateSubsOnEvent('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.to('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().updateSubsOnEvent('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.to('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().updateSubsOnEvent('a'); }).not.to["throw"](); expect(function() { return binding().removeEvent('a