it("should call deserializedFromTemplate function on the instantiated objects", function() { var component = objects.Comp.create(); component.element = document.createElement("div"); component.element.setAttribute("data-montage-id", "myDiv"); component.child = objects.Comp.create(); var htmlDocument = document.implementation.createHTMLDocument(""); var script = htmlDocument.createElement("script"); script.setAttribute("type", Template._SCRIPT_TYPE); script.textContent = Serializer.create().initWithRequire(require).serialize({owner: component}); htmlDocument.head.appendChild(script); var latch, componentDeserializedFromTemplateCount, childDeserializedFromTemplateCount, template = Template.create().initWithDocument(htmlDocument); template.instantiateWithComponent(component, function() { componentDeserializedFromTemplateCount = component.deserializedFromTemplateCount; childDeserializedFromTemplateCount = component.child.deserializedFromTemplateCount; latch = true; }); waitsFor(function() { return latch; }); runs(function() { expect(componentDeserializedFromTemplateCount).toBe(0); expect(childDeserializedFromTemplateCount).toBe(1); }); });
it("should export all template objects into templateObjects", function() { var component = objects.Comp.create(), htmlDocument = document.implementation.createHTMLDocument(""), script = htmlDocument.createElement("script"), latch; component.element = document.createElement("div"); component.element.setAttribute("data-montage-id", "myDiv"); script.setAttribute("type", Template._SCRIPT_TYPE); script.textContent = Serializer.create().initWithRequire(require).serialize({owner: component, object1: 1, object2: "string"}); htmlDocument.head.appendChild(script); var template = Template.create().initWithDocument(htmlDocument); component.templateObjects = {}; template.instantiateWithComponent(component, function() { latch = true; }); waitsFor(function() { return latch; }); runs(function() { expect(Object.keys(component.templateObjects).length).toBe(2); }) });