From 5654f2f4e267a98880a1da5595799ab763a695de Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Thu, 16 Jul 2015 08:27:59 -0700 Subject: [PATCH] test(dom_renderer): test that properties on the root element can be changed. Closes #3013 Closes #3085 --- .../dom/dom_renderer_integration_spec.ts | 45 ++++++++++--------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/modules/angular2/test/render/dom/dom_renderer_integration_spec.ts b/modules/angular2/test/render/dom/dom_renderer_integration_spec.ts index ab4dbc3deb..e2caa04951 100644 --- a/modules/angular2/test/render/dom/dom_renderer_integration_spec.ts +++ b/modules/angular2/test/render/dom/dom_renderer_integration_spec.ts @@ -61,7 +61,8 @@ export function main() { }); })); - it('should update any element property/attributes/class/style independent of the compilation', + + it('should update any element property/attributes/class/style independent of the compilation on the root element and other elements', inject([AsyncTestCompleter, DomTestbed], (async, tb: DomTestbed) => { tb.compileAndMerge(someComponent, [ @@ -72,26 +73,30 @@ export function main() { }) ]) .then((protoViewMergeMappings) => { + + var checkSetters = (elr, el) => { + tb.renderer.setElementProperty(elr, 'tabIndex', 1); + expect((el).tabIndex).toEqual(1); + + tb.renderer.setElementClass(elr, 'a', true); + expect(DOM.hasClass(el, 'a')).toBe(true); + tb.renderer.setElementClass(elr, 'a', false); + expect(DOM.hasClass(el, 'a')).toBe(false); + + tb.renderer.setElementStyle(elr, 'width', '10px'); + expect(DOM.getStyle(el, 'width')).toEqual('10px'); + tb.renderer.setElementStyle(elr, 'width', null); + expect(DOM.getStyle(el, 'width')).toEqual(''); + + tb.renderer.setElementAttribute(elr, 'someAttr', 'someValue'); + expect(DOM.getAttribute(el, 'some-attr')).toEqual('someValue'); + }; + var rootView = tb.createView(protoViewMergeMappings[0]); - - var elr = elRef(rootView.viewRef, 1); - var el = DOM.childNodes(rootView.hostElement)[0]; - tb.renderer.setElementProperty(elr, 'value', 'hello'); - expect((el).value).toEqual('hello'); - - tb.renderer.setElementClass(elr, 'a', true); - expect((DOM.childNodes(rootView.hostElement)[0]).value) - .toEqual('hello'); - tb.renderer.setElementClass(elr, 'a', false); - expect(DOM.hasClass(el, 'a')).toBe(false); - - tb.renderer.setElementStyle(elr, 'width', '10px'); - expect(DOM.getStyle(el, 'width')).toEqual('10px'); - tb.renderer.setElementStyle(elr, 'width', null); - expect(DOM.getStyle(el, 'width')).toEqual(''); - - tb.renderer.setElementAttribute(elr, 'someAttr', 'someValue'); - expect(DOM.getAttribute(el, 'some-attr')).toEqual('someValue'); + // root element + checkSetters(elRef(rootView.viewRef, 0), rootView.hostElement); + // nested elements + checkSetters(elRef(rootView.viewRef, 1), DOM.firstChild(rootView.hostElement)); async.done(); });