UNPKG

@danielkalen/simplybind

Version:

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

69 lines (45 loc) 1.63 kB
suite ".of() method", ()-> test "Can only accept non-primitive objects", ()-> expect ()-> SimplyBind(0).of([]) .not.to.throw() expect ()-> SimplyBind(0).of(()->) .not.to.throw() expect ()-> SimplyBind(0).of({}) .not.to.throw() expect ()-> SimplyBind(0).of(new Date()) .not.to.throw() if isBrowser expect ()-> SimplyBind(0).of($('<div />')[0]) .not.to.throw() if window.Map and window.Set and window.Symbol expect ()-> SimplyBind(0).of(new Map()) .not.to.throw() expect ()-> SimplyBind(0).of(new WeakMap()) .not.to.throw() expect ()-> SimplyBind(0).of(new Set()) .not.to.throw() expect ()-> SimplyBind(0).of(new WeakSet()) .not.to.throw() expect ()-> SimplyBind(0).of(Symbol(0)) .to.throw() expect ()-> SimplyBind(0).of(SimplyBind('prop1').of(objectA)) .not.to.throw() expect ()-> SimplyBind(0).of('s') .to.throw() expect ()-> SimplyBind(0).of(0) .to.throw() expect ()-> SimplyBind(0).of(true) .to.throw() expect ()-> SimplyBind(0).of(null) .to.throw() expect ()-> SimplyBind(0).of(undefined) .to.throw() test "Will extract and use the subject bound object from the instance if passed a binding instance", ()-> 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' expect(objectB.prop4).to.equal 'ofBounded'