From bf609f0e56d6d9e701caebb56b9f3feaf6d38475 Mon Sep 17 00:00:00 2001 From: vsavkin Date: Thu, 8 Jan 2015 09:11:33 -0800 Subject: [PATCH] refactor(tests): exctract createElement into a helper --- modules/core/test/compiler/compiler_spec.js | 22 +++--- .../core/test/compiler/integration_spec.js | 23 +++--- .../pipeline/directive_parser_spec.js | 40 +++++------ .../pipeline/element_binder_builder_spec.js | 33 ++++----- .../pipeline/element_binding_marker_spec.js | 24 +++---- .../test/compiler/pipeline/pipeline_spec.js | 26 +++---- .../pipeline/property_binding_parser_spec.js | 24 +++---- .../proto_element_injector_builder_spec.js | 42 +++++------ .../pipeline/proto_view_builder_spec.js | 24 +++---- .../text_interpolation_parser_spec.js | 18 ++--- .../compiler/pipeline/view_splitter_spec.js | 26 +++---- modules/core/test/compiler/selector_spec.js | 10 +-- .../compiler/shadow_dom/content_tag_spec.js | 22 +++--- .../compiler/shadow_dom/light_dom_spec.js | 22 +++--- modules/core/test/compiler/view_spec.js | 72 +++++++++---------- modules/core/test/compiler/viewport_spec.js | 18 ++--- .../directives/test/ng_non_bindable_spec.js | 8 +-- modules/directives/test/ng_repeat_spec.js | 8 +-- modules/test_lib/src/test_lib.dart | 5 ++ modules/test_lib/src/test_lib.es6 | 7 ++ 20 files changed, 206 insertions(+), 268 deletions(-) diff --git a/modules/core/test/compiler/compiler_spec.js b/modules/core/test/compiler/compiler_spec.js index 968f92ad88..b44bdd786a 100644 --- a/modules/core/test/compiler/compiler_spec.js +++ b/modules/core/test/compiler/compiler_spec.js @@ -1,4 +1,4 @@ -import {describe, beforeEach, it, expect, ddescribe, iit} from 'test_lib/test_lib'; +import {describe, beforeEach, it, expect, ddescribe, iit, el} from 'test_lib/test_lib'; import {DOM} from 'facade/dom'; import {List} from 'facade/collection'; @@ -32,19 +32,19 @@ export function main() { var compiler = createCompiler( (parent, current, control) => { current.inheritedProtoView = rootProtoView; }); - compiler.compile(MainComponent, createElement('
')).then( (protoView) => { + compiler.compile(MainComponent, el('
')).then( (protoView) => { expect(protoView).toBe(rootProtoView); done(); }); }); it('should use the given element', (done) => { - var el = createElement('
'); + var element = el('
'); var compiler = createCompiler( (parent, current, control) => { current.inheritedProtoView = new ProtoView(current.element, null); }); - compiler.compile(MainComponent, el).then( (protoView) => { - expect(protoView.element).toBe(el); + compiler.compile(MainComponent, element).then( (protoView) => { + expect(protoView.element).toBe(element); done(); }); }); @@ -60,7 +60,7 @@ export function main() { }); it('should load nested components', (done) => { - var mainEl = createElement('
'); + var mainEl = el('
'); var compiler = createCompiler( (parent, current, control) => { current.inheritedProtoView = new ProtoView(current.element, null); current.inheritedElementBinder = current.inheritedProtoView.bindElement(null); @@ -77,14 +77,14 @@ export function main() { }); it('should cache components', (done) => { - var el = createElement('
'); + var element = el('
'); var compiler = createCompiler( (parent, current, control) => { current.inheritedProtoView = new ProtoView(current.element, null); }); var firstProtoView; - compiler.compile(MainComponent, el).then( (protoView) => { + compiler.compile(MainComponent, element).then( (protoView) => { firstProtoView = protoView; - return compiler.compile(MainComponent, el); + return compiler.compile(MainComponent, element); }).then( (protoView) => { expect(firstProtoView).toBe(protoView); done(); @@ -151,7 +151,3 @@ class MockStep extends CompileStep { this.processClosure(parent, current, control); } } - -function createElement(html) { - return DOM.createTemplate(html).content.firstChild; -} diff --git a/modules/core/test/compiler/integration_spec.js b/modules/core/test/compiler/integration_spec.js index 032a639690..7bb9fa9aac 100644 --- a/modules/core/test/compiler/integration_spec.js +++ b/modules/core/test/compiler/integration_spec.js @@ -1,4 +1,4 @@ -import {describe, xit, it, expect, beforeEach, ddescribe, iit} from 'test_lib/test_lib'; +import {describe, xit, it, expect, beforeEach, ddescribe, iit, el} from 'test_lib/test_lib'; import {DOM} from 'facade/dom'; @@ -33,7 +33,7 @@ export function main() { } it('should consume text node changes', (done) => { - compiler.compile(MyComp, createElement('
{{ctxProp}}
')).then((pv) => { + compiler.compile(MyComp, el('
{{ctxProp}}
')).then((pv) => { createView(pv); ctx.ctxProp = 'Hello World!'; @@ -44,7 +44,7 @@ export function main() { }); it('should consume element binding changes', (done) => { - compiler.compile(MyComp, createElement('
')).then((pv) => { + compiler.compile(MyComp, el('
')).then((pv) => { createView(pv); ctx.ctxProp = 'Hello World!'; @@ -56,7 +56,7 @@ export function main() { }); it('should consume directive watch expression change.', (done) => { - compiler.compile(MyComp, createElement('
')).then((pv) => { + compiler.compile(MyComp, el('
')).then((pv) => { createView(pv); ctx.ctxProp = 'Hello World!'; @@ -69,7 +69,7 @@ export function main() { }); it('should support nested components.', (done) => { - compiler.compile(MyComp, createElement('')).then((pv) => { + compiler.compile(MyComp, el('')).then((pv) => { createView(pv); cd.detectChanges(); @@ -80,7 +80,7 @@ export function main() { }); it('should support template directives via `