QUnit.test("setting nested object", function(){ var m = new DefineMap({}); m.set({foo: {}}); m.set({foo: {}}); QUnit.deepEqual(m.get(), {foo: {}}); });
QUnit.test("set multiple props", function(){ var map = new DefineMap(); map.set({a: 0, b: 2}); QUnit.deepEqual(map.get(), {a: 0, b:2}); map.set({a: 2}, true); QUnit.deepEqual(map.get(), {a: 2}); map.set({foo: {bar: "VALUE"}}); QUnit.deepEqual(map.get(), {foo: {bar: "VALUE"}, a: 2}); });
QUnit.test("Components can be instantiated with <content> - with scope - leakScope false", function() { var ComponentConstructor = Component.extend({ leakScope: false, tag: "new-instantiation-content-leakscope-false", view: "Hello <content>{{message}}</content>", ViewModel: { message: {default: "world"} } }); var scopeVM = new DefineMap({}); var componentInstance = new ComponentConstructor({ content: "<em>{{message}}</em>", scope: scopeVM }); var element = componentInstance.element; // Start off without the key defined in the scope; with leakScope false, // no message will be rendered QUnit.equal(element.innerHTML, "Hello <em></em>", "content is rendered with the provided scope"); // Set the key in the scope; now a message will be rendered scopeVM.set("message", "mundo"); QUnit.equal(element.innerHTML, "Hello <em>mundo</em>", "content updates with the provided scope"); });
test("compute(defineMap, 'property.names') works (#20)", function(){ var map = new DefineMap(); var c = compute(map, "foo.bar"); c.on("change", function(ev, newVal){ QUnit.equal(newVal, 2); }); map.set("foo", new DefineMap()); map.foo.set("bar", 2); });
QUnit.test("creating a new key doesn't cause two changes", 1, function(){ var map = new DefineMap(); var oi = new Observation(function(){ return map.serialize(); },null,{ updater: function(newVal){ QUnit.deepEqual(newVal, {a: 1}, "updated right"); } }); oi.start(); map.set("a", 1); });
QUnit.test("serialize responds to added props", function(){ var map = new DefineMap(); var oi = new Observation(function(){ return map.serialize(); },null,{ updater: function(newVal){ QUnit.deepEqual(newVal, {a: 1, b: 2}, "updated right"); } }); oi.start(); map.set({a: 1, b: 2}); });
QUnit.test("get and set can setup expandos", function(){ var map = new DefineMap(); var oi = new Observation(function(){ return map.get("foo"); },null,{ updater: function(newVal){ QUnit.equal(newVal, "bar", "updated to bar"); } }); oi.start(); map.set("foo","bar"); });
QUnit.test("#if should not re-render children", function(){ var count = 0; var view = stache("{{#eq(a,b)}} {{increment()}} {{/eq}}"); var map = new DefineMap({ a: 1, b: 1 }); map.set("increment", function(){ count++; }); view(map); map.assign({ a: 2, b: 2 }); map.assign({ a: 3, b: 3 }); QUnit.equal(count, 1, "count should be called only once"); });
QUnit.test("set an already initialized null property", function(){ var map = new DefineMap({ foo: null }); map.set({ foo: null }); equal(map.foo, null); });
QUnit.test("get with dynamically added properties", function(){ var map = new DefineMap(); map.set("a",1); map.set("b",2); QUnit.deepEqual(map.get(), {a: 1, b:2}); });