From a59594ad19c1184f3cf0569d3ab434dbc0d33070 Mon Sep 17 00:00:00 2001 From: James deBoer Date: Tue, 18 Mar 2014 11:20:44 -0700 Subject: [PATCH 1/3] feat(mock): Move JQuery to angular/mock so it can be used more widely --- lib/mock/jquery.dart | 129 ++++++++++++++++++ lib/mock/module.dart | 2 + test/_specs.dart | 125 ----------------- .../jquery_mock.dart} | 7 +- 4 files changed, 133 insertions(+), 130 deletions(-) create mode 100644 lib/mock/jquery.dart rename test/{_specs_spec.dart => mock/jquery_mock.dart} (97%) diff --git a/lib/mock/jquery.dart b/lib/mock/jquery.dart new file mode 100644 index 000000000..09e055aa2 --- /dev/null +++ b/lib/mock/jquery.dart @@ -0,0 +1,129 @@ +part of angular.mock; + +// TODO(deboer): This belongs is a seperate unit testing package. + +es(String html) { + var div = new DivElement(); + div.setInnerHtml(html, treeSanitizer: new NullTreeSanitizer()); + return div.nodes; +} + +e(String html) => es(html).first; + + + +$(selector) { + return new JQuery(selector); +} + +// TODO(deboer): This class is not used in tests. +class GetterSetter { + Getter getter(String key) => null; + Setter setter(String key) => null; +} +var getterSetter = new GetterSetter(); + +class JQuery extends DelegatingList { + JQuery([selector]) : super([]) { + if (selector == null) { + // do nothing; + } else if (selector is String) { + addAll(es(selector)); + } else if (selector is List) { + addAll(selector); + } else if (selector is Node) { + add(selector); + } else { + throw selector; + } + } + + _toHtml(node, [bool outer = false]) { + if (node is Comment) { + return ''; + } else if (node is DocumentFragment) { + var acc = ''; + node.childNodes.forEach((n) { acc += _toHtml(n, true); }); + return acc; + } else if (node is Element) { + // Remove all the "ng-binding" internal classes + node = node.clone(true) as Element; + node.classes.remove('ng-binding'); + node.querySelectorAll(".ng-binding").forEach((Element e) { + e.classes.remove('ng-binding'); + }); + var htmlString = outer ? node.outerHtml : node.innerHtml; + // Strip out empty class attributes. This seems like a Dart bug... + return htmlString.replaceAll(' class=""', ''); + } else { + throw "JQuery._toHtml not implemented for node type [${node.nodeType}]"; + } + } + + _renderedText(n, [bool notShadow = false]) { + if (n is List) { + return n.map((nn) => _renderedText(nn)).join(""); + } + + if (n is Comment) return ''; + + if (!notShadow && n is Element && n.shadowRoot != null) { + var shadowText = n.shadowRoot.text; + var domText = _renderedText(n, true); + return shadowText.replaceFirst("SHADOW-CONTENT", domText); + } + + if (n.nodes == null || n.nodes.length == 0) return n.text; + + return n.nodes.map((cn) => _renderedText(cn)).join(""); + } + + accessor(Function getter, Function setter, [value, single=false]) { + // TODO(dart): ?value does not work, since value was passed. :-( + var setterMode = value != null; + var result = setterMode ? this : ''; + forEach((node) { + if (setterMode) { + setter(node, value); + } else { + result = single ? getter(node) : '$result${getter(node)}'; + } + }); + return result; + } + + html([String html]) => accessor( + (n) => _toHtml(n), + (n, v) => n.setInnerHtml(v, treeSanitizer: new NullTreeSanitizer()), + html); + val([String text]) => accessor((n) => n.value, (n, v) => n.value = v); + text([String text]) => accessor((n) => n.text, (n, v) => n.text = v, text); + contents() => fold(new JQuery(), (jq, node) => jq..addAll(node.nodes)); + toString() => fold('', (html, node) => '$html${_toHtml(node, true)}'); + eq(num childIndex) => $(this[childIndex]); + remove(_) => forEach((n) => n.remove()); + attr([String name, String value]) => accessor( + (n) => n.attributes[name], + (n, v) => n.attributes[name] = v, + value, + true); + prop([String name]) => accessor( + (n) => getterSetter.getter(name)(n), + (n, v) => getterSetter.setter(name)(n, v), + null, + true); + textWithShadow() => fold('', (t, n) => '${t}${_renderedText(n)}'); + find(selector) => fold(new JQuery(), (jq, n) => jq..addAll( + (n is Element ? (n as Element).querySelectorAll(selector) : []))); + hasClass(String name) => fold(false, (hasClass, node) => + hasClass || (node is Element && (node as Element).classes.contains(name))); + addClass(String name) => forEach((node) => + (node is Element) ? (node as Element).classes.add(name) : null); + removeClass(String name) => forEach((node) => + (node is Element) ? (node as Element).classes.remove(name) : null); + css(String name, [String value]) => accessor( + (Element n) => n.style.getPropertyValue(name), + (Element n, v) => n.style.setProperty(name, value), value); + children() => new JQuery(this[0].childNodes); + shadowRoot() => new JQuery((this[0] as Element).shadowRoot); +} diff --git a/lib/mock/module.dart b/lib/mock/module.dart index 8700e9120..2b2876af1 100644 --- a/lib/mock/module.dart +++ b/lib/mock/module.dart @@ -7,6 +7,7 @@ import 'dart:html'; import 'dart:js' as js; import 'package:angular/angular.dart'; import 'package:angular/utils.dart' as utils; +import 'package:collection/wrappers.dart' show DelegatingList; import 'package:di/di.dart'; import 'package:di/dynamic_injector.dart'; import 'package:unittest/mock.dart'; @@ -16,6 +17,7 @@ export 'zone.dart'; part 'debug.dart'; part 'exception_handler.dart'; part 'http_backend.dart'; +part 'jquery.dart'; part 'log.dart'; part 'probe.dart'; part 'test_bed.dart'; diff --git a/test/_specs.dart b/test/_specs.dart index 75d7906e6..daf36bcf1 100644 --- a/test/_specs.dart +++ b/test/_specs.dart @@ -4,7 +4,6 @@ import 'dart:html'; import 'package:unittest/unittest.dart' as unit; import 'package:angular/angular.dart'; import 'package:angular/mock/module.dart'; -import 'package:collection/wrappers.dart' show DelegatingList; import 'jasmine_syntax.dart' as jasmine_syntax; @@ -17,14 +16,6 @@ export 'package:angular/animate/module.dart'; export 'package:angular/mock/module.dart'; export 'package:perf_api/perf_api.dart'; -es(String html) { - var div = new DivElement(); - div.setInnerHtml(html, treeSanitizer: new NullTreeSanitizer()); - return div.nodes; -} - -e(String html) => es(html).first; - Expect expect(actual, [unit.Matcher matcher = null]) { if (matcher != null) { unit.expect(actual, matcher); @@ -129,122 +120,6 @@ class ExceptionContains extends unit.Matcher { } } -$(selector) { - return new JQuery(selector); -} - - -class GetterSetter { - Getter getter(String key) => null; - Setter setter(String key) => null; -} -var getterSetter = new GetterSetter(); - -class JQuery extends DelegatingList { - JQuery([selector]) : super([]) { - if (selector == null) { - // do nothing; - } else if (selector is String) { - addAll(es(selector)); - } else if (selector is List) { - addAll(selector); - } else if (selector is Node) { - add(selector); - } else { - throw selector; - } - } - - _toHtml(node, [bool outer = false]) { - if (node is Comment) { - return ''; - } else if (node is DocumentFragment) { - var acc = ''; - node.childNodes.forEach((n) { acc += _toHtml(n, true); }); - return acc; - } else if (node is Element) { - // Remove all the "ng-binding" internal classes - node = node.clone(true) as Element; - node.classes.remove('ng-binding'); - node.querySelectorAll(".ng-binding").forEach((Element e) { - e.classes.remove('ng-binding'); - }); - var htmlString = outer ? node.outerHtml : node.innerHtml; - // Strip out empty class attributes. This seems like a Dart bug... - return htmlString.replaceAll(' class=""', ''); - } else { - throw "JQuery._toHtml not implemented for node type [${node.nodeType}]"; - } - } - - _renderedText(n, [bool notShadow = false]) { - if (n is List) { - return n.map((nn) => _renderedText(nn)).join(""); - } - - if (n is Comment) return ''; - - if (!notShadow && n is Element && n.shadowRoot != null) { - var shadowText = n.shadowRoot.text; - var domText = _renderedText(n, true); - return shadowText.replaceFirst("SHADOW-CONTENT", domText); - } - - if (n.nodes == null || n.nodes.length == 0) return n.text; - - return n.nodes.map((cn) => _renderedText(cn)).join(""); - } - - accessor(Function getter, Function setter, [value, single=false]) { - // TODO(dart): ?value does not work, since value was passed. :-( - var setterMode = value != null; - var result = setterMode ? this : ''; - forEach((node) { - if (setterMode) { - setter(node, value); - } else { - result = single ? getter(node) : '$result${getter(node)}'; - } - }); - return result; - } - - html([String html]) => accessor( - (n) => _toHtml(n), - (n, v) => n.setInnerHtml(v, treeSanitizer: new NullTreeSanitizer()), - html); - val([String text]) => accessor((n) => n.value, (n, v) => n.value = v); - text([String text]) => accessor((n) => n.text, (n, v) => n.text = v, text); - contents() => fold(new JQuery(), (jq, node) => jq..addAll(node.nodes)); - toString() => fold('', (html, node) => '$html${_toHtml(node, true)}'); - eq(num childIndex) => $(this[childIndex]); - remove(_) => forEach((n) => n.remove()); - attr([String name, String value]) => accessor( - (n) => n.attributes[name], - (n, v) => n.attributes[name] = v, - value, - true); - prop([String name]) => accessor( - (n) => getterSetter.getter(name)(n), - (n, v) => getterSetter.setter(name)(n, v), - null, - true); - textWithShadow() => fold('', (t, n) => '${t}${_renderedText(n)}'); - find(selector) => fold(new JQuery(), (jq, n) => jq..addAll( - (n is Element ? (n as Element).querySelectorAll(selector) : []))); - hasClass(String name) => fold(false, (hasClass, node) => - hasClass || (node is Element && (node as Element).classes.contains(name))); - addClass(String name) => forEach((node) => - (node is Element) ? (node as Element).classes.add(name) : null); - removeClass(String name) => forEach((node) => - (node is Element) ? (node as Element).classes.remove(name) : null); - css(String name, [String value]) => accessor( - (Element n) => n.style.getPropertyValue(name), - (Element n, v) => n.style.setProperty(name, value), value); - children() => new JQuery(this[0].childNodes); - shadowRoot() => new JQuery((this[0] as Element).shadowRoot); -} - _injectify(fn) { // The function does two things: // First: if the it() passed a function, we wrap it in diff --git a/test/_specs_spec.dart b/test/mock/jquery_mock.dart similarity index 97% rename from test/_specs_spec.dart rename to test/mock/jquery_mock.dart index 9d4aec4bf..dec0163cb 100644 --- a/test/_specs_spec.dart +++ b/test/mock/jquery_mock.dart @@ -1,11 +1,8 @@ -library _specs_spec; +library angular.mock.jquery_spec; -import '_specs.dart'; +import '../_specs.dart'; main() { - - - describe('jquery', () { describe('html', () { it('get', (){ From c7b6911102d862c72f1d29d1627c80312813fe0e Mon Sep 17 00:00:00 2001 From: James deBoer Date: Tue, 18 Mar 2014 12:28:57 -0700 Subject: [PATCH 2/3] feat(test bed): TestBed.compile now returns a JQuery object --- lib/mock/jquery.dart | 3 + lib/mock/test_bed.dart | 4 +- test/core_dom/compiler_spec.dart | 4 +- test/core_dom/directive_spec.dart | 5 +- test/core_dom/event_handler_spec.dart | 39 ++++++---- test/core_dom/ng_element_spec.dart | 42 +++++----- test/directive/ng_bind_spec.dart | 6 +- test/directive/ng_bind_template_spec.dart | 4 +- test/directive/ng_class_spec.dart | 20 ++--- test/directive/ng_form_spec.dart | 16 ++-- test/directive/ng_include_spec.dart | 10 +-- test/directive/ng_model_spec.dart | 86 ++++++++++----------- test/directive/ng_pluralize_spec.dart | 94 +++++++++++------------ test/directive/ng_style_spec.dart | 6 +- test/directive/ng_switch_spec.dart | 48 ++++++------ test/routing/ng_bind_route_spec.dart | 6 +- test/routing/ng_view_spec.dart | 36 ++++----- test/routing/routing_spec.dart | 38 ++++----- 18 files changed, 241 insertions(+), 226 deletions(-) diff --git a/lib/mock/jquery.dart b/lib/mock/jquery.dart index 09e055aa2..b28393526 100644 --- a/lib/mock/jquery.dart +++ b/lib/mock/jquery.dart @@ -126,4 +126,7 @@ class JQuery extends DelegatingList { (Element n, v) => n.style.setProperty(name, value), value); children() => new JQuery(this[0].childNodes); shadowRoot() => new JQuery((this[0] as Element).shadowRoot); + + get classes => first.classes; + get className => first.className; } diff --git a/lib/mock/test_bed.dart b/lib/mock/test_bed.dart index 7147492b5..c7d755776 100644 --- a/lib/mock/test_bed.dart +++ b/lib/mock/test_bed.dart @@ -34,7 +34,7 @@ class TestBed { * * An option [scope] parameter can be supplied to link it with non root scope. */ - Element compile(html, {Scope scope, DirectiveMap directives}) { + JQuery compile(html, {Scope scope, DirectiveMap directives}) { var injector = this.injector; if (scope != null) { injector = injector.createChild([new Module()..value(Scope, scope)]); @@ -53,7 +53,7 @@ class TestBed { directives = injector.get(DirectiveMap); } rootView = compiler(rootElements, directives)(injector, rootElements); - return rootElement; + return $(rootElement); } /** diff --git a/test/core_dom/compiler_spec.dart b/test/core_dom/compiler_spec.dart index 54e9b9d30..f36a9683f 100644 --- a/test/core_dom/compiler_spec.dart +++ b/test/core_dom/compiler_spec.dart @@ -580,7 +580,7 @@ void main() { _.rootScope.apply(); - expect(element.text).toContain('my data'); + expect(element.text()).toContain('my data'); }); it('should expose a ancestor controller to the scope of its children thru a undecorated element', (TestBed _) { @@ -593,7 +593,7 @@ void main() { _.rootScope.apply(); - expect(element.text).toContain('my data'); + expect(element.text()).toContain('my data'); }); }); diff --git a/test/core_dom/directive_spec.dart b/test/core_dom/directive_spec.dart index b80f5f4f6..91ae0f37f 100644 --- a/test/core_dom/directive_spec.dart +++ b/test/core_dom/directive_spec.dart @@ -4,14 +4,13 @@ import '../_specs.dart'; main() { describe('NodeAttrs', () { - var element; var nodeAttrs; TestBed _; beforeEach((TestBed tb) { _ = tb; - element = _.compile('
'); - nodeAttrs = new NodeAttrs(element); + _.compile('
'); + nodeAttrs = new NodeAttrs(_.rootElement); }); it('should transform names to camel case', () { diff --git a/test/core_dom/event_handler_spec.dart b/test/core_dom/event_handler_spec.dart index c84fd05ec..5b1529706 100644 --- a/test/core_dom/event_handler_spec.dart +++ b/test/core_dom/event_handler_spec.dart @@ -25,22 +25,33 @@ class BarComponent { main() { describe('EventHandler', () { + TestBed _; + beforeEachModule((Module module) { module..type(FooController); module..type(BarComponent); module..value(Element, document.body); }); + beforeEach((TestBed tb) { + _ = tb; + }); + // Not sure why this doesn't work. afterEach(() { document.body.children.clear(); }); - it('shoud register and handle event', inject((TestBed _) { - document.body.append(_.compile( + appendToBody(str) { + _.compile(str); + document.body.append(_.rootElement); + } + + it('shoud register and handle event', inject(() { + appendToBody( '''
-
''')); + '''); document.querySelector('[on-abc]').dispatchEvent(new Event('abc')); var fooScope = _.getScope(document.querySelector('[foo]')); @@ -48,11 +59,11 @@ main() { document.body.children.clear(); })); - it('shoud register and handle event with long name', inject((TestBed _) { - document.body.append(_.compile( + it('shoud register and handle event with long name', inject(() { + appendToBody( '''
-
''')); + '''); document.querySelector('[on-my-new-event]').dispatchEvent(new Event('myNewEvent')); var fooScope = _.getScope(document.querySelector('[foo]')); @@ -60,11 +71,11 @@ main() { document.body.children.clear(); })); - it('shoud have model updates applied correctly', inject((TestBed _) { - document.body.append(_.compile( + it('shoud have model updates applied correctly', inject(() { + appendToBody( '''
{{ctrl.description}}
-
''')); + '''); var el = document.querySelector('[on-abc]'); el.dispatchEvent(new Event('abc')); _.rootScope.apply(); @@ -72,8 +83,8 @@ main() { document.body.children.clear(); })); - it('shoud register event when shadow dom is used', async((TestBed _) { - document.body.append(_.compile('')); + it('shoud register event when shadow dom is used', async(() { + appendToBody(''); microLeap(); @@ -85,13 +96,13 @@ main() { document.body.children.clear(); })); - it('shoud handle event within content only once', async(inject((TestBed _) { - document.body.append(_.compile( + it('shoud handle event within content only once', async(inject(() { + appendToBody( '''
-
''')); + '''); microLeap(); diff --git a/test/core_dom/ng_element_spec.dart b/test/core_dom/ng_element_spec.dart index d497b06bd..3e9debbbd 100644 --- a/test/core_dom/ng_element_spec.dart +++ b/test/core_dom/ng_element_spec.dart @@ -5,13 +5,23 @@ import 'dart:html' as dom; void main() { describe('ngElement', () { + TestBed _; + NgAnimate animate; + NgElement ngElement; + JQuery element; + + beforeEach((TestBed testBed, NgAnimate ngAnimate) { + _ = testBed; + animate = ngAnimate; + }); - it('should add classes on domWrite to the element', - (TestBed _, NgAnimate animate) { + compile(str) { + element = _.compile(str); + ngElement = new NgElement(_.rootElement, _.rootScope, animate); + } - var scope = _.rootScope; - var element = _.compile('
'); - var ngElement = new NgElement(element, scope, animate); + it('should add classes on domWrite to the element', () { + compile('
'); ngElement.addClass('one'); ngElement.addClass('two three'); @@ -20,19 +30,15 @@ void main() { expect(element.classes.contains(className)).toBe(false); }); - scope.apply(); + _.rootScope.apply(); ['one','two','three'].forEach((className) { expect(element.classes.contains(className)).toBe(true); }); }); - it('should remove classes on domWrite to the element', - (TestBed _, NgAnimate animate) { - - var scope = _.rootScope; - var element = _.compile('
'); - var ngElement = new NgElement(element, scope, animate); + it('should remove classes on domWrite to the element', () { + compile('
'); ngElement.removeClass('one'); ngElement.removeClass('two'); @@ -43,7 +49,7 @@ void main() { }); expect(element.classes.contains('four')).toBe(true); - scope.apply(); + _.rootScope.apply(); ['one','two','three'].forEach((className) { expect(element.classes.contains(className)).toBe(false); @@ -51,12 +57,8 @@ void main() { expect(element.classes.contains('four')).toBe(true); }); - it('should always apply the last dom operation on the given className', - (TestBed _, NgAnimate animate) { - - var scope = _.rootScope; - var element = _.compile('
'); - var ngElement = new NgElement(element, scope, animate); + it('should always apply the last dom operation on the given className', () { + compile('
'); ngElement.addClass('one'); ngElement.addClass('one'); @@ -64,7 +66,7 @@ void main() { expect(element.classes.contains('one')).toBe(false); - scope.apply(); + _.rootScope.apply(); expect(element.classes.contains('one')).toBe(false); diff --git a/test/directive/ng_bind_spec.dart b/test/directive/ng_bind_spec.dart index 81bfaf89b..32c7529ec 100644 --- a/test/directive/ng_bind_spec.dart +++ b/test/directive/ng_bind_spec.dart @@ -23,17 +23,17 @@ main() { scope.apply(() { scope.context['value'] = null; }); - expect(element.text).toEqual(''); + expect(element.text()).toEqual(''); scope.apply(() { scope.context['value'] = true; }); - expect(element.text).toEqual('true'); + expect(element.text()).toEqual('true'); scope.apply(() { scope.context['value'] = 1; }); - expect(element.text).toEqual('1'); + expect(element.text()).toEqual('1'); }); }); } diff --git a/test/directive/ng_bind_template_spec.dart b/test/directive/ng_bind_template_spec.dart index 3516c7e4e..892378f54 100644 --- a/test/directive/ng_bind_template_spec.dart +++ b/test/directive/ng_bind_template_spec.dart @@ -15,12 +15,12 @@ main() { scope.context['name'] = 'Heisenberg'; scope.apply(); - expect(element.text).toEqual('Hello Heisenberg!'); + expect(element.text()).toEqual('Hello Heisenberg!'); scope.context['salutation'] = 'Good-Bye'; scope.apply(); - expect(element.text).toEqual('Good-Bye Heisenberg!'); + expect(element.text()).toEqual('Good-Bye Heisenberg!'); }); }); } diff --git a/test/directive/ng_class_spec.dart b/test/directive/ng_class_spec.dart index 9b80985be..c21650a50 100644 --- a/test/directive/ng_class_spec.dart +++ b/test/directive/ng_class_spec.dart @@ -169,8 +169,8 @@ main() { it('should ngClass odd/even', () { var element = _.compile('
    • '); _.rootScope.apply(); - var e1 = element.nodes[1]; - var e2 = element.nodes[2]; + var e1 = element.children()[1]; + var e2 = element.children()[2]; expect(e1.classes.contains('existing')).toBeTruthy(); expect(e1.classes.contains('odd')).toBeTruthy(); expect(e2.classes.contains('existing')).toBeTruthy(); @@ -184,8 +184,8 @@ main() { 'ng-class-odd="\'odd\'" ng-class-even="\'even\'">{{\$index}}' + '
        '); _.rootScope.apply(); - var e1 = element.nodes[1]; - var e2 = element.nodes[2]; + var e1 = element.children()[1]; + var e2 = element.children()[2]; expect(e1.classes.contains('plainClass')).toBeTruthy(); expect(e1.classes.contains('odd')).toBeTruthy(); @@ -201,8 +201,8 @@ main() { 'ng-class-odd="[\'C\', \'D\']" ng-class-even="[\'E\', \'F\']">' + '
          '); _.rootScope.apply(); - var e1 = element.nodes[1]; - var e2 = element.nodes[2]; + var e1 = element.children()[1]; + var e2 = element.children()[2]; expect(e1.classes.contains('A')).toBeTruthy(); expect(e1.classes.contains('B')).toBeTruthy(); @@ -277,8 +277,8 @@ main() { _.rootScope.context['items'] = ['a','b']; _.rootScope.apply(); - var e1 = element.nodes[1]; - var e2 = element.nodes[2]; + var e1 = element.children()[1]; + var e2 = element.children()[2]; expect(e1.classes.contains('odd')).toBeTruthy(); expect(e1.classes.contains('even')).toBeFalsy(); @@ -299,8 +299,8 @@ main() { _.rootScope.context['items'] = ['b','a']; _.rootScope.apply(); - var e1 = element.nodes[1]; - var e2 = element.nodes[2]; + var e1 = element.children()[1]; + var e2 = element.children()[2]; expect(e1.classes.contains('odd')).toBeTruthy(); expect(e1.classes.contains('even')).toBeFalsy(); diff --git a/test/directive/ng_form_spec.dart b/test/directive/ng_form_spec.dart index 30d159443..2c6abdaf7 100644 --- a/test/directive/ng_form_spec.dart +++ b/test/directive/ng_form_spec.dart @@ -695,9 +695,9 @@ void main() { }); it('should reset each of the controls to be untouched only when the form has a valid submission', (Scope scope, TestBed _) { - var form = _.compile('
          ' + - ' ' + - '
          '); + _.compile('
          ' + + ' ' + + '
          '); NgForm formModel = _.rootScope.context['duperForm']; var model = _.rootScope.context['i'].directive(NgModel); @@ -708,7 +708,7 @@ void main() { expect(model.touched).toBe(true); expect(formModel.invalid).toBe(true); - _.triggerEvent(form, 'submit'); + _.triggerEvent(_.rootElement, 'submit'); expect(formModel.touched).toBe(true); expect(model.touched).toBe(true); @@ -717,7 +717,7 @@ void main() { scope.apply(() { scope.context['myModel'] = 'value'; }); - _.triggerEvent(form, 'submit'); + _.triggerEvent(_.rootElement, 'submit'); expect(formModel.valid).toBe(true); expect(formModel.touched).toBe(false); @@ -729,9 +729,9 @@ void main() { Scope s = _.rootScope; s.context['name'] = 'cool'; - var form = _.compile('
          ' + - ' ' + - '
          '); + _.compile('
          ' + + ' ' + + '
          '); NgForm formModel = s.context['myForm']; Probe probe = s.context['i']; diff --git a/test/directive/ng_include_spec.dart b/test/directive/ng_include_spec.dart index d279c1c9f..c8e5dcefc 100644 --- a/test/directive/ng_include_spec.dart +++ b/test/directive/ng_include_spec.dart @@ -13,13 +13,13 @@ main() { var element = _.compile('
          '); - expect(element.innerHtml).toEqual(''); + expect(element.html()).toEqual(''); microLeap(); // load the template from cache. scope.applyInZone(() { scope.context['name'] = 'Vojta'; }); - expect(element.text).toEqual('my name is Vojta'); + expect(element.text()).toEqual('my name is Vojta'); })); it('should fetch template from url using interpolation', async((Scope scope, TemplateCache cache) { @@ -28,18 +28,18 @@ main() { var element = _.compile('
          '); - expect(element.innerHtml).toEqual(''); + expect(element.html()).toEqual(''); scope.applyInZone(() { scope.context['name'] = 'Vojta'; scope.context['template'] = 'tpl1.html'; }); - expect(element.text).toEqual('My name is Vojta'); + expect(element.text()).toEqual('My name is Vojta'); scope.applyInZone(() { scope.context['template'] = 'tpl2.html'; }); - expect(element.text).toEqual('I am Vojta'); + expect(element.text()).toEqual('I am Vojta'); })); }); diff --git a/test/directive/ng_model_spec.dart b/test/directive/ng_model_spec.dart index 3a2b68c42..475522293 100644 --- a/test/directive/ng_model_spec.dart +++ b/test/directive/ng_model_spec.dart @@ -163,39 +163,39 @@ void main() { it('should leave input unchanged when text does not represent a valid number', (Injector i) { var modelFieldName = 'modelForNumFromInvalid1'; - var element = _.compile(''); - dom.querySelector('body').append(element); + _.compile(''); + dom.querySelector('body').append(_.rootElement); // This test will progressively enter the text '1e1' // '1' is a valid number. // '1e' is not a valid number. // '1e1' is again a valid number (with an exponent) - simulateTypingText(element, '1'); - _.triggerEvent(element, 'change'); - expect(element.value).toEqual('1'); + simulateTypingText(_.rootElement, '1'); + _.triggerEvent(_.rootElement, 'change'); + expect(_.rootElement.value).toEqual('1'); expect(_.rootScope.context[modelFieldName]).toEqual(1); - simulateTypingText(element, 'e'); - // Because the text is not a valid number, the element value is empty. - expect(element.value).toEqual(''); + simulateTypingText(_.rootElement, 'e'); + // Because the text is not a valid number, the _.rootElement value is empty. + expect(_.rootElement.value).toEqual(''); // When the input is invalid, the model is [double.NAN]: - _.triggerEvent(element, 'change'); + _.triggerEvent(_.rootElement, 'change'); expect(_.rootScope.context[modelFieldName].isNaN).toBeTruthy(); - simulateTypingText(element, '1'); - _.triggerEvent(element, 'change'); - expect(element.value).toEqual('1e1'); + simulateTypingText(_.rootElement, '1'); + _.triggerEvent(_.rootElement, 'change'); + expect(_.rootElement.value).toEqual('1e1'); expect(_.rootScope.context[modelFieldName]).toEqual(10); }); it('should not reformat user input to equivalent numeric representation', (Injector i) { var modelFieldName = 'modelForNumFromInvalid2'; - var element = _.compile(''); - dom.querySelector('body').append(element); + _.compile(''); + dom.querySelector('body').append(_.rootElement); - simulateTypingText(element, '1e-1'); - expect(element.value).toEqual('1e-1'); + simulateTypingText(_.rootElement, '1e-1'); + expect(_.rootElement.value).toEqual('1e-1'); expect(_.rootScope.context[modelFieldName]).toEqual(0.1); }); @@ -573,28 +573,28 @@ void main() { describe('type="checkbox"', () { it('should update input value from model', (Scope scope) { - var element = _.compile(''); + _.compile(''); scope.apply(() { scope.context['model'] = true; }); - expect(element.checked).toBe(true); + expect(_.rootElement.checked).toBe(true); scope.apply(() { scope.context['model'] = false; }); - expect(element.checked).toBe(false); + expect(_.rootElement.checked).toBe(false); }); it('should render as dirty when checked', (Scope scope) { - var element = _.compile(''); + _.compile(''); Probe probe = _.rootScope.context['i']; var model = probe.directive(NgModel); expect(model.pristine).toEqual(true); expect(model.dirty).toEqual(false); - _.triggerEvent(element, 'change'); + _.triggerEvent(_.rootElement, 'change'); expect(model.pristine).toEqual(false); expect(model.dirty).toEqual(true); @@ -602,57 +602,57 @@ void main() { it('should update input value from model using ng-true-value/false', (Scope scope) { - var element = _.compile(''); + _.compile(''); scope.apply(() { scope.context['model'] = 1; }); - expect(element.checked).toBe(true); + expect(_.rootElement.checked).toBe(true); scope.apply(() { scope.context['model'] = 0; }); - expect(element.checked).toBe(false); + expect(_.rootElement.checked).toBe(false); - element.checked = true; - _.triggerEvent(element, 'change'); + _.rootElement.checked = true; + _.triggerEvent(_.rootElement, 'change'); expect(scope.context['model']).toBe(1); - element.checked = false; - _.triggerEvent(element, 'change'); + _.rootElement.checked = false; + _.triggerEvent(_.rootElement, 'change'); expect(scope.context['model']).toBe(0); }); it('should allow non boolean values like null, 0, 1', (Scope scope) { - var element = _.compile(''); + _.compile(''); scope.apply(() { scope.context['model'] = 0; }); - expect(element.checked).toBe(false); + expect(_.rootElement.checked).toBe(false); scope.apply(() { scope.context['model'] = 1; }); - expect(element.checked).toBe(true); + expect(_.rootElement.checked).toBe(true); scope.apply(() { scope.context['model'] = null; }); - expect(element.checked).toBe(false); + expect(_.rootElement.checked).toBe(false); }); it('should update model from the input value', (Scope scope) { - var element = _.compile(''); + _.compile(''); - element.checked = true; - _.triggerEvent(element, 'change'); + _.rootElement.checked = true; + _.triggerEvent(_.rootElement, 'change'); expect(scope.context['model']).toBe(true); - element.checked = false; - _.triggerEvent(element, 'change'); + _.rootElement.checked = false; + _.triggerEvent(_.rootElement, 'change'); expect(scope.context['model']).toBe(false); }); @@ -862,7 +862,7 @@ void main() { }); it('should render as dirty when checked', (Scope scope) { - var element = _.compile( + _.compile( '
          ' + ' ' + ' ' + @@ -872,8 +872,8 @@ void main() { var model = probe.directive(NgModel); - var input1 = element.querySelector("#on"); - var input2 = element.querySelector("#off"); + var input1 = _.rootElement.querySelector("#on"); + var input2 = _.rootElement.querySelector("#off"); scope.apply(); @@ -904,7 +904,7 @@ void main() { }); it('should only render the input value upon the next digest', (Scope scope) { - var element = _.compile( + _.compile( '
          ' + ' ' + ' ' + @@ -1293,13 +1293,13 @@ void main() { }); it('should set the model to be untouched when the model is reset', () { - var input = _.compile(''); + _.compile(''); var model = _.rootScope.context['i'].directive(NgModel); expect(model.touched).toBe(false); expect(model.untouched).toBe(true); - _.triggerEvent(input, 'blur'); + _.triggerEvent(_.rootElement, 'blur'); expect(model.touched).toBe(true); expect(model.untouched).toBe(false); diff --git a/test/directive/ng_pluralize_spec.dart b/test/directive/ng_pluralize_spec.dart index b70f4cfdf..a5ddb72ed 100644 --- a/test/directive/ng_pluralize_spec.dart +++ b/test/directive/ng_pluralize_spec.dart @@ -36,95 +36,95 @@ main() { it('should show single/plural strings', () { _.rootScope.context['email'] = '0'; _.rootScope.apply(); - expect(element.text).toEqual('You have no new email'); - expect(elementAlt.text).toEqual('You have no new email'); + expect(element.text()).toEqual('You have no new email'); + expect(elementAlt.text()).toEqual('You have no new email'); _.rootScope.context['email'] = '0'; _.rootScope.apply(); - expect(element.text).toEqual('You have no new email'); - expect(elementAlt.text).toEqual('You have no new email'); + expect(element.text()).toEqual('You have no new email'); + expect(elementAlt.text()).toEqual('You have no new email'); _.rootScope.context['email'] = 1; _.rootScope.apply(); - expect(element.text).toEqual('You have one new email'); - expect(elementAlt.text).toEqual('You have one new email'); + expect(element.text()).toEqual('You have one new email'); + expect(elementAlt.text()).toEqual('You have one new email'); _.rootScope.context['email'] = 0.01; _.rootScope.apply(); - expect(element.text).toEqual('You have 0.01 new emails'); - expect(elementAlt.text).toEqual('You have 0.01 new emails'); + expect(element.text()).toEqual('You have 0.01 new emails'); + expect(elementAlt.text()).toEqual('You have 0.01 new emails'); _.rootScope.context['email'] = '0.1'; _.rootScope.apply(); - expect(element.text).toEqual('You have 0.1 new emails'); - expect(elementAlt.text).toEqual('You have 0.1 new emails'); + expect(element.text()).toEqual('You have 0.1 new emails'); + expect(elementAlt.text()).toEqual('You have 0.1 new emails'); _.rootScope.context['email'] = 2; _.rootScope.apply(); - expect(element.text).toEqual('You have 2 new emails'); - expect(elementAlt.text).toEqual('You have 2 new emails'); + expect(element.text()).toEqual('You have 2 new emails'); + expect(elementAlt.text()).toEqual('You have 2 new emails'); _.rootScope.context['email'] = -0.1; _.rootScope.apply(); - expect(element.text).toEqual('You have -0.1 new emails'); - expect(elementAlt.text).toEqual('You have -0.1 new emails'); + expect(element.text()).toEqual('You have -0.1 new emails'); + expect(elementAlt.text()).toEqual('You have -0.1 new emails'); _.rootScope.context['email'] = '-0.01'; _.rootScope.apply(); - expect(element.text).toEqual('You have -0.01 new emails'); - expect(elementAlt.text).toEqual('You have -0.01 new emails'); + expect(element.text()).toEqual('You have -0.01 new emails'); + expect(elementAlt.text()).toEqual('You have -0.01 new emails'); _.rootScope.context['email'] = -2; _.rootScope.apply(); - expect(element.text).toEqual('You have -2 new emails'); - expect(elementAlt.text).toEqual('You have -2 new emails'); + expect(element.text()).toEqual('You have -2 new emails'); + expect(elementAlt.text()).toEqual('You have -2 new emails'); _.rootScope.context['email'] = -1; _.rootScope.apply(); - expect(element.text).toEqual('You have negative email. Whohoo!'); - expect(elementAlt.text).toEqual('You have negative email. Whohoo!'); + expect(element.text()).toEqual('You have negative email. Whohoo!'); + expect(elementAlt.text()).toEqual('You have negative email. Whohoo!'); }); it('should show single/plural strings with mal-formed inputs', () { _.rootScope.context['email'] = ''; _.rootScope.apply(); - expect(element.text).toEqual(''); - expect(elementAlt.text).toEqual(''); + expect(element.text()).toEqual(''); + expect(elementAlt.text()).toEqual(''); _.rootScope.context['email'] = null; _.rootScope.apply(); - expect(element.text).toEqual(''); - expect(elementAlt.text).toEqual(''); + expect(element.text()).toEqual(''); + expect(elementAlt.text()).toEqual(''); _.rootScope.context['email'] = 'a3'; _.rootScope.apply(); - expect(element.text).toEqual(''); - expect(elementAlt.text).toEqual(''); + expect(element.text()).toEqual(''); + expect(elementAlt.text()).toEqual(''); _.rootScope.context['email'] = '011'; _.rootScope.apply(); - expect(element.text).toEqual('You have 11 new emails'); - expect(elementAlt.text).toEqual('You have 11 new emails'); + expect(element.text()).toEqual('You have 11 new emails'); + expect(elementAlt.text()).toEqual('You have 11 new emails'); _.rootScope.context['email'] = '-011'; _.rootScope.apply(); - expect(element.text).toEqual('You have -11 new emails'); - expect(elementAlt.text).toEqual('You have -11 new emails'); + expect(element.text()).toEqual('You have -11 new emails'); + expect(elementAlt.text()).toEqual('You have -11 new emails'); _.rootScope.context['email'] = '1fff'; _.rootScope.apply(); - expect(element.text).toEqual(''); - expect(elementAlt.text).toEqual(''); + expect(element.text()).toEqual(''); + expect(elementAlt.text()).toEqual(''); _.rootScope.context['email'] = '0aa22'; _.rootScope.apply(); - expect(element.text).toEqual(''); - expect(elementAlt.text).toEqual(''); + expect(element.text()).toEqual(''); + expect(elementAlt.text()).toEqual(''); _.rootScope.context['email'] = '000001'; _.rootScope.apply(); - expect(element.text).toEqual('You have one new email'); - expect(elementAlt.text).toEqual('You have one new email'); + expect(element.text()).toEqual('You have one new email'); + expect(elementAlt.text()).toEqual('You have one new email'); }); }); @@ -138,7 +138,7 @@ main() { ''); _.rootScope.context['email'] = '0'; _.rootScope.apply(); - expect(element.text).toEqual(''); + expect(element.text()).toEqual(''); })); }); @@ -165,28 +165,28 @@ main() { _.rootScope.context['viewCount'] = 0; _.rootScope.apply(); - expect(element.text).toEqual('Nobody is viewing.'); - expect(elementAlt.text).toEqual('Nobody is viewing.'); + expect(element.text()).toEqual('Nobody is viewing.'); + expect(elementAlt.text()).toEqual('Nobody is viewing.'); _.rootScope.context['viewCount'] = 1; _.rootScope.apply(); - expect(element.text).toEqual('Igor is viewing.'); - expect(elementAlt.text).toEqual('Igor is viewing.'); + expect(element.text()).toEqual('Igor is viewing.'); + expect(elementAlt.text()).toEqual('Igor is viewing.'); _.rootScope.context['viewCount'] = 2; _.rootScope.apply(); - expect(element.text).toEqual('Igor and Misko are viewing.'); - expect(elementAlt.text).toEqual('Igor and Misko are viewing.'); + expect(element.text()).toEqual('Igor and Misko are viewing.'); + expect(elementAlt.text()).toEqual('Igor and Misko are viewing.'); _.rootScope.context['viewCount'] = 3; _.rootScope.apply(); - expect(element.text).toEqual('Igor, Misko and one other person are viewing.'); - expect(elementAlt.text).toEqual('Igor, Misko and one other person are viewing.'); + expect(element.text()).toEqual('Igor, Misko and one other person are viewing.'); + expect(elementAlt.text()).toEqual('Igor, Misko and one other person are viewing.'); _.rootScope.context['viewCount'] = 4; _.rootScope.apply(); - expect(element.text).toEqual('Igor, Misko and 2 other people are viewing.'); - expect(elementAlt.text).toEqual('Igor, Misko and 2 other people are viewing.'); + expect(element.text()).toEqual('Igor, Misko and 2 other people are viewing.'); + expect(elementAlt.text()).toEqual('Igor, Misko and 2 other people are viewing.'); })); }); }); diff --git a/test/directive/ng_style_spec.dart b/test/directive/ng_style_spec.dart index 2a7a6a9eb..ed973cc29 100644 --- a/test/directive/ng_style_spec.dart +++ b/test/directive/ng_style_spec.dart @@ -10,14 +10,14 @@ void main() { beforeEach((TestBed tb) => _ = tb); it('should set', () { - dom.Element element = _.compile('
          '); + _.compile('
          '); _.rootScope.apply(); - expect(element.style.height).toEqual('40px'); + expect(_.rootElement.style.height).toEqual('40px'); }); it('should silently ignore undefined style', () { - dom.Element element = _.compile('
          '); + var element = _.compile('
          '); _.rootScope.apply(); expect(element.classes.contains('ng-exception')).toBeFalsy(); }); diff --git a/test/directive/ng_switch_spec.dart b/test/directive/ng_switch_spec.dart index 86e415092..dbbbfb269 100644 --- a/test/directive/ng_switch_spec.dart +++ b/test/directive/ng_switch_spec.dart @@ -15,23 +15,23 @@ void main() { '
          second:{{name}}
          ' + '
          true:{{name}}
          ' + '
          '); - expect(element.innerHtml).toEqual( + expect(element.html()).toEqual( ''); _.rootScope.context['select'] = 1; _.rootScope.apply(); - expect(element.text).toEqual('first:'); + expect(element.text()).toEqual('first:'); _.rootScope.context['name'] = "shyam"; _.rootScope.apply(); - expect(element.text).toEqual('first:shyam'); + expect(element.text()).toEqual('first:shyam'); _.rootScope.context['select'] = 2; _.rootScope.apply(); - expect(element.text).toEqual('second:shyam'); + expect(element.text()).toEqual('second:shyam'); _.rootScope.context['name'] = 'misko'; _.rootScope.apply(); - expect(element.text).toEqual('second:misko'); + expect(element.text()).toEqual('second:misko'); _.rootScope.context['select'] = true; _.rootScope.apply(); - expect(element.text).toEqual('true:misko'); + expect(element.text()).toEqual('true:misko'); }); @@ -43,25 +43,25 @@ void main() { '
        • second:{{name}}
        • ' + '
        • true:{{name}}
        • ' + '
        '); - expect(element.innerHtml).toEqual('' + expect(element.html()).toEqual('' '' '' ''); _.rootScope.context['select'] = 1; _.rootScope.apply(); - expect(element.text).toEqual('first:, first too:'); + expect(element.text()).toEqual('first:, first too:'); _.rootScope.context['name'] = "shyam"; _.rootScope.apply(); - expect(element.text).toEqual('first:shyam, first too:shyam'); + expect(element.text()).toEqual('first:shyam, first too:shyam'); _.rootScope.context['select'] = 2; _.rootScope.apply(); - expect(element.text).toEqual('second:shyam'); + expect(element.text()).toEqual('second:shyam'); _.rootScope.context['name'] = 'misko'; _.rootScope.apply(); - expect(element.text).toEqual('second:misko'); + expect(element.text()).toEqual('second:misko'); _.rootScope.context['select'] = true; _.rootScope.apply(); - expect(element.text).toEqual('true:misko'); + expect(element.text()).toEqual('true:misko'); }); @@ -72,10 +72,10 @@ void main() { '
        other
        ' + ''); _.rootScope.apply(); - expect(element.text).toEqual('other'); + expect(element.text()).toEqual('other'); _.rootScope.context['select'] = 1; _.rootScope.apply(); - expect(element.text).toEqual('one'); + expect(element.text()).toEqual('one'); }); @@ -87,10 +87,10 @@ void main() { '
      • , other too
      • ' + '
      '); _.rootScope.apply(); - expect(element.text).toEqual('other, other too'); + expect(element.text()).toEqual('other, other too'); _.rootScope.context['select'] = 1; _.rootScope.apply(); - expect(element.text).toEqual('one'); + expect(element.text()).toEqual('one'); }); @@ -105,10 +105,10 @@ void main() { '
    • other too
    • ' + '
    '); _.rootScope.apply(); - expect(element.text).toEqual('always other, other too '); + expect(element.text()).toEqual('always other, other too '); _.rootScope.context['select'] = 1; _.rootScope.apply(); - expect(element.text).toEqual('always one '); + expect(element.text()).toEqual('always one '); })); @@ -128,10 +128,10 @@ void main() { '
  • 8
  • ' + '
'); _.rootScope.apply(); - expect(element.text).toEqual('135678'); + expect(element.text()).toEqual('135678'); _.rootScope.context['select'] = 1; _.rootScope.apply(); - expect(element.text).toEqual('12368'); + expect(element.text()).toEqual('12368'); }); @@ -149,10 +149,10 @@ void main() { '
  • 7
  • ' + ''); _.rootScope.apply(); - expect(element.text).toEqual('3567'); + expect(element.text()).toEqual('3567'); _.rootScope.context['select'] = 1; _.rootScope.apply(); - expect(element.text).toEqual('236'); + expect(element.text()).toEqual('236'); })); @@ -164,7 +164,7 @@ void main() { _.rootScope.context['url'] = 'a'; _.rootScope.apply(); expect(_.rootScope.context['name']).toEqual('works'); - expect(element.text).toEqual('works'); + expect(element.text()).toEqual('works'); }); @@ -185,7 +185,7 @@ void main() { _.rootScope.apply(); var child1 = getChildScope(); expect(child1).toBeNotNull(); - expect(element.text).toEqual('works'); + expect(element.text()).toEqual('works'); var destroyListener = jasmine.createSpy('watch listener'); var watcher = child1.on(ScopeEvent.DESTROY).listen(destroyListener); diff --git a/test/routing/ng_bind_route_spec.dart b/test/routing/ng_bind_route_spec.dart index 7a9dc79c8..af601266f 100644 --- a/test/routing/ng_bind_route_spec.dart +++ b/test/routing/ng_bind_route_spec.dart @@ -19,13 +19,13 @@ main() { it('should inject null RouteProvider when no ng-bind-route', async(() { - Element root = _.compile('
    '); + _.compile('
    '); expect(_.rootScope.context['routeProbe'].injector.get(RouteProvider)).toBeNull(); })); it('should inject RouteProvider with correct flat route', async(() { - Element root = _.compile( + _.compile( '
    '); expect(_.rootScope.context['routeProbe'].injector.get(RouteProvider).routeName) .toEqual('library'); @@ -33,7 +33,7 @@ main() { it('should inject RouteProvider with correct nested route', async(() { - Element root = _.compile( + _.compile( '
    ' '
    ' '
    ' diff --git a/test/routing/ng_view_spec.dart b/test/routing/ng_view_spec.dart index 35a057766..ff151d079 100644 --- a/test/routing/ng_view_spec.dart +++ b/test/routing/ng_view_spec.dart @@ -28,20 +28,20 @@ main() { it('should switch template', async(() { - Element root = _.compile(''); - expect(root.text).toEqual(''); + var root = _.compile(''); + expect(root.text()).toEqual(''); router.route('/foo'); microLeap(); - expect(root.text).toEqual('Foo'); + expect(root.text()).toEqual('Foo'); router.route('/bar'); microLeap(); - expect(root.text).toEqual('Bar'); + expect(root.text()).toEqual('Bar'); router.route('/foo'); microLeap(); - expect(root.text).toEqual('Foo'); + expect(root.text()).toEqual('Foo'); })); @@ -51,26 +51,26 @@ main() { router.route('/foo'); microLeap(); - Element root = _.compile(''); - expect(root.text).toEqual(''); + var root = _.compile(''); + expect(root.text()).toEqual(''); _.rootScope.apply(); microLeap(); - expect(root.text).toEqual('Foo'); + expect(root.text()).toEqual('Foo'); })); it('should clear template when route is deactivated', async(() { - Element root = _.compile(''); - expect(root.text).toEqual(''); + var root = _.compile(''); + expect(root.text()).toEqual(''); router.route('/foo'); microLeap(); - expect(root.text).toEqual('Foo'); + expect(root.text()).toEqual('Foo'); router.route('/baz'); // route without a template microLeap(); - expect(root.text).toEqual(''); + expect(root.text()).toEqual(''); })); }); @@ -106,26 +106,26 @@ main() { // meantime we are disabling it. if (!identical(1, 1.0)) { it('should switch nested templates', async(() { - Element root = _.compile(''); - expect(root.text).toEqual(''); + var root = _.compile(''); + expect(root.text()).toEqual(''); router.route('/library/all'); microLeap(); - expect(root.text).toEqual('LibraryBooks'); + expect(root.text()).toEqual('LibraryBooks'); router.route('/library/1234'); microLeap(); - expect(root.text).toEqual('LibraryBook 1234'); + expect(root.text()).toEqual('LibraryBook 1234'); // nothing should change here router.route('/library/1234/overview'); microLeap(); - expect(root.text).toEqual('LibraryBook 1234'); + expect(root.text()).toEqual('LibraryBook 1234'); // nothing should change here router.route('/library/1234/read'); microLeap(); - expect(root.text).toEqual('LibraryRead Book 1234'); + expect(root.text()).toEqual('LibraryRead Book 1234'); })); } }); diff --git a/test/routing/routing_spec.dart b/test/routing/routing_spec.dart index 9d6d83d1c..6c63a40ce 100644 --- a/test/routing/routing_spec.dart +++ b/test/routing/routing_spec.dart @@ -159,14 +159,14 @@ main() { _.injector.get(TemplateCache) .put('foo.html', new HttpResponse(200, '

    Foo

    ')); - Element root = _.compile(''); - expect(root.text).toEqual(''); + var root = _.compile(''); + expect(root.text()).toEqual(''); router.route('/foo'); microLeap(); expect(enterCount).toBe(1); - expect(root.text).toEqual('Foo'); + expect(root.text()).toEqual('Foo'); })); @@ -232,19 +232,19 @@ main() { _.injector.get(TemplateCache) .put('foo.html', new HttpResponse(200, '

    Foo

    ')); - Element root = _.compile(''); - expect(root.text).toEqual(''); + var root = _.compile(''); + expect(root.text()).toEqual(''); router.route('/foo'); microLeap(); - expect(root.text).toEqual('Foo'); + expect(root.text()).toEqual('Foo'); expect(leaveCount).toBe(0); router.route('/bar'); microLeap(); - expect(root.text).toEqual(''); + expect(root.text()).toEqual(''); expect(leaveCount).toBe(1); })); @@ -264,13 +264,13 @@ main() { _.injector.get(TemplateCache) .put('foo.html', new HttpResponse(200, '
    Old!
    ')); - Element root = _.compile(''); - expect(root.text).toEqual(''); + var root = _.compile(''); + expect(root.text()).toEqual(''); router.route('/foo'); microLeap(); - expect(root.text).toEqual('New!'); + expect(root.text()).toEqual('New!'); })); @@ -289,13 +289,13 @@ main() { _.injector.get(TemplateCache) .put('foo.html', new HttpResponse(200, '
    Old!
    ')); - Element root = _.compile(''); - expect(root.text).toEqual(''); + var root = _.compile(''); + expect(root.text()).toEqual(''); router.route('/foo'); microLeap(); - expect(root.text).toEqual('New!'); + expect(root.text()).toEqual('New!'); })); @@ -314,14 +314,14 @@ main() { _.injector.get(TemplateCache) .put('foo.html', new HttpResponse(200, '
    {{\'World\' | hello}}
    ')); - Element root = _.compile(''); - expect(root.text).toEqual(''); + var root = _.compile(''); + expect(root.text()).toEqual(''); router.route('/foo'); microLeap(); _.rootScope.apply(); - expect(root.text).toEqual('Hello, World!'); + expect(root.text()).toEqual('Hello, World!'); })); @@ -340,14 +340,14 @@ main() { _.injector.get(TemplateCache) .put('foo.html', new HttpResponse(200, '
    {{\'World\' | hello}}
    ')); - Element root = _.compile(''); - expect(root.text).toEqual(''); + var root = _.compile(''); + expect(root.text()).toEqual(''); router.route('/foo'); microLeap(); _.rootScope.apply(); - expect(root.text).toEqual('Hello, World!'); + expect(root.text()).toEqual('Hello, World!'); })); }); From ae10367254af5163ec5e581d50517f5bbe02cce9 Mon Sep 17 00:00:00 2001 From: James deBoer Date: Tue, 18 Mar 2014 12:39:28 -0700 Subject: [PATCH 3/3] chore(jquery): Remove unneeded JQuery wrappers --- test/bootstrap_spec.dart | 2 +- test/core_dom/compiler_spec.dart | 82 +++++++++++++++--------------- test/directive/ng_repeat_spec.dart | 6 +-- 3 files changed, 44 insertions(+), 46 deletions(-) diff --git a/test/bootstrap_spec.dart b/test/bootstrap_spec.dart index dc3d986f2..33571b369 100644 --- a/test/bootstrap_spec.dart +++ b/test/bootstrap_spec.dart @@ -13,7 +13,7 @@ void main() { it('should default to whole page', () { var body = setBody('
    {{"works"}}
    '); ngBootstrap(); - expect($(body).html()).toEqual('
    works
    '); + expect(body.html()).toEqual('
    works
    '); }); it('should compile starting at ng-app node', () { diff --git a/test/core_dom/compiler_spec.dart b/test/core_dom/compiler_spec.dart index f36a9683f..afa21bd21 100644 --- a/test/core_dom/compiler_spec.dart +++ b/test/core_dom/compiler_spec.dart @@ -45,7 +45,7 @@ void main() { beforeEach(inject((TestBed tb) => _ = tb)); it('should compile basic hello world', () { - var element = $(_.compile('
    ')); + var element = _.compile('
    '); _.rootScope.context['name'] = 'angular'; @@ -59,17 +59,17 @@ void main() { }); it('should compile a comment with no directives around', () { - var element = $(_.compile('
    ')); + var element = _.compile('
    '); expect(element.html()).toEqual(''); }); it('should compile a comment when the parent has a directive', () { - var element = $(_.compile('
    ')); + var element = _.compile('
    '); expect(element.html()).toEqual(''); }); it('should compile a directive in a child', () { - var element = $(_.compile('
    ')); + var element = _.compile('
    '); _.rootScope.context['name'] = 'angular'; @@ -79,7 +79,7 @@ void main() { }); it('should compile repeater', () { - var element = $(_.compile('
    ')); + var element = _.compile('
    '); _.rootScope.context['items'] = ['A', 'b']; expect(element.text()).toEqual(''); @@ -93,10 +93,10 @@ void main() { }); it('should compile a text child of a basic repeater', () { - var element = $(_.compile( + var element = _.compile( '
    ' + '{{r}}' + - '
    ')); + '
    '); _.rootScope.apply(); expect(element.text()).toEqual('12'); }); @@ -109,18 +109,18 @@ void main() { }); it('should compile a sibling template directive', () { - var element = $(_.compile( + var element = _.compile( '
    ' '' '
    {{value}}
    ' - '
    ')); + '
    '); _.rootScope.apply(); expect(element.text()).toEqual('blank12'); }); it('should compile repeater with children', (Compiler $compile) { - var element = $(_.compile('
    ')); + var element = _.compile('
    '); _.rootScope.context['items'] = ['A', 'b']; @@ -134,7 +134,7 @@ void main() { }); it('should compile text', (Compiler $compile) { - var element = $(_.compile('
    {{name}}!
    ')); + var element = _.compile('
    {{name}}!
    '); _.rootScope.context['name'] = 'OK'; microLeap(); @@ -143,12 +143,12 @@ void main() { }); it('should compile nested repeater', (Compiler $compile) { - var element = $(_.compile( + var element = _.compile( '
    ' + '
      ' + '
    • {{li}}
    • ' + '
    ' + - '
    ')); + ''); _.rootScope.context['uls'] = [['A'], ['b']]; @@ -157,7 +157,7 @@ void main() { }); it('should compile two directives with the same selector', (Logger log) { - var element = $(_.compile('
    ')); + var element = _.compile('
    '); _.rootScope.apply(); @@ -166,7 +166,7 @@ void main() { it('should compile a directive that ignores children', (Logger log) { // The ng-repeat comes first, so it is not ignored, but the children *are* - var element = $(_.compile('
    ')); + var element = _.compile('
    '); _.rootScope.apply(); @@ -176,7 +176,7 @@ void main() { describe("interpolation", () { it('should interpolate attribute nodes', () { - var element = $(_.compile('
    ')); + var element = _.compile('
    '); _.rootScope.context['name'] = 'angular'; @@ -185,7 +185,7 @@ void main() { }); it('should interpolate text nodes', () { - var element = $(_.compile('
    {{name}}
    ')); + var element = _.compile('
    {{name}}
    '); _.rootScope.context['name'] = 'angular'; @@ -217,7 +217,7 @@ void main() { }); it('should select on element', async((NgZone zone) { - var element = $(_.compile(r'
    ')); + var element = _.compile(r'
    '); microLeap(); _.rootScope.apply(); expect(element.textWithShadow()).toEqual('INNER()'); @@ -240,7 +240,7 @@ void main() { it('should create a simple component', async((NgZone zone) { _.rootScope.context['name'] = 'OUTTER'; - var element = $(_.compile(r'
    {{name}}:{{name}}
    ')); + var element = _.compile(r'
    {{name}}:{{name}}
    '); microLeap(); _.rootScope.apply(); expect(element.textWithShadow()).toEqual('OUTTER:INNER(OUTTER)'); @@ -249,7 +249,7 @@ void main() { it('should create a component that can access parent scope', async((NgZone zone) { _.rootScope.context['fromParent'] = "should not be used"; _.rootScope.context['val'] = "poof"; - var element = $(_.compile('')); + var element = _.compile(''); microLeap(); _.rootScope.apply(); @@ -257,7 +257,7 @@ void main() { })); it('should behave nicely if a mapped attribute is missing', async((NgZone zone) { - var element = $(_.compile('')); + var element = _.compile(''); microLeap(); _.rootScope.apply(); @@ -266,7 +266,7 @@ void main() { it('should behave nicely if a mapped attribute evals to null', async((NgZone zone) { _.rootScope.context['val'] = null; - var element = $(_.compile('')); + var element = _.compile(''); microLeap(); _.rootScope.apply(); @@ -274,7 +274,7 @@ void main() { })); it('should create a component with I/O', async(() { - var element = $(_.compile(r'
    ')); + var element = _.compile(r'
    '); microLeap(); _.rootScope.context['name'] = 'misko'; @@ -292,7 +292,7 @@ void main() { })); xit('should should not create any watchers if no attributes are specified', async((Profiler perf) { - var element = $(_.compile(r'
    ')); + var element = _.compile(r'
    '); microLeap(); _.injector.get(Scope).apply(); // Re-enable once we can publish these numbers @@ -306,7 +306,7 @@ void main() { it('should create a component with I/O and "=" binding value should be available', async(() { _.rootScope.context['name'] = 'misko'; - var element = $(_.compile(r'
    ')); + var element = _.compile(r'
    '); microLeap(); var component = _.rootScope.context['ioComponent']; @@ -319,7 +319,7 @@ void main() { it('should create a component with I/O bound to controller and "=" binding value should be available', async(() { _.rootScope.context['done'] = false; - var element = $(_.compile(r'
    ')); + var element = _.compile(r'
    '); expect(_.injector).toBeDefined(); @@ -355,7 +355,7 @@ void main() { })); it('should create a map attribute to controller', async(() { - var element = $(_.compile(r'
    ')); + var element = _.compile(r'
    '); microLeap(); IoControllerComponent component = _.rootScope.context['ioComponent']; @@ -372,7 +372,7 @@ void main() { it('should create a unpublished component with I/O bound to controller and "=" binding value should be available', async(() { _.rootScope.context['name'] = 'misko'; _.rootScope.context['done'] = false; - var element = $(_.compile(r'
    ')); + var element = _.compile(r'
    '); microLeap(); UnpublishedIoControllerComponent component = _.rootScope.context['ioComponent']; @@ -393,12 +393,12 @@ void main() { it('should error on incorrect mapping', async(() { expect(() { - var element = $(_.compile(r'
    ')); + var element = _.compile(r'
    '); }).toThrow("Unknown mapping 'foo\' for attribute 'attr'."); })); it('should support filters in attribute expressions', async(() { - var element = $(_.compile(r'''''')); + var element = _.compile(r''''''); ExprAttrComponent component = _.rootScope.context['exprAttrComponent']; _.rootScope.apply(); expect(component.expr).toEqual('Hello, Misko!'); @@ -408,12 +408,12 @@ void main() { it('should error on non-asignable-mapping', async(() { expect(() { - var element = $(_.compile(r'
    ')); + var element = _.compile(r'
    '); }).toThrow("Expression '1+2' is not assignable in mapping '@1+2' for attribute 'attr'."); })); it('should expose mapped attributes as camel case', async(() { - var element = $(_.compile('')); + var element = _.compile(''); microLeap(); _.rootScope.apply(); var componentScope = _.rootScope.context['camelCase']; @@ -423,7 +423,7 @@ void main() { // TODO: This is a terrible test it('should throw an exception if required directive is missing', async(() { try { - var element = $(_.compile('')); + var element = _.compile(''); } catch (e) { var text = '$e'; expect(text).toContain('No provider found for'); @@ -433,14 +433,14 @@ void main() { })); it('should publish component controller into the scope', async((NgZone zone) { - var element = $(_.compile(r'
    ')); + var element = _.compile(r'
    '); microLeap(); _.rootScope.apply(); expect(element.textWithShadow()).toEqual('WORKED'); })); it('should publish directive controller into the scope', async((NgZone zone) { - var element = $(_.compile(r'
    {{ctrlName.value}}
    ')); + var element = _.compile(r'
    {{ctrlName.value}}
    '); microLeap(); _.rootScope.apply(); @@ -448,13 +448,13 @@ void main() { })); it('should "publish" controller to injector under provided publishTypes', () { - var element = $(_.compile(r'
    ')); + var element = _.compile(r'
    '); expect(PublishTypesAttrDirective._injector.get(PublishTypesAttrDirective)). toBe(PublishTypesAttrDirective._injector.get(PublishTypesDirectiveSuperType)); }); it('should allow repeaters over controllers', async((Logger logger) { - var element = $(_.compile(r'')); + var element = _.compile(r''); _.rootScope.apply(); microLeap(); @@ -549,7 +549,7 @@ void main() { describe('controller scoping', () { it('should make controllers available to sibling and child controllers', async((Logger log) { - var element = $(_.compile('')); + var element = _.compile(''); microLeap(); expect(log.result()).toEqual('TabComponent-0; LocalAttrDirective-0; PaneComponent-1; LocalAttrDirective-0; PaneComponent-2; LocalAttrDirective-0'); @@ -559,14 +559,14 @@ void main() { // Getting the parent offsets correct while descending the template is tricky. If we get it wrong, this // test case will create too many TabCompoenents. - var element = $(_.compile('
    ')); + var element = _.compile('
    '); microLeap(); expect(log.result()).toEqual('Ignore; TabComponent-0; LocalAttrDirective-0; PaneComponent-1; LocalAttrDirective-0'); })); it('should reuse controllers for transclusions', async((Logger log) { - var element = $(_.compile('
    view
    ')); + var element = _.compile('
    view
    '); microLeap(); _.rootScope.apply(); @@ -601,7 +601,7 @@ void main() { describe('NgDirective', () { it('should allow creation of a new scope', () { _.rootScope.context['name'] = 'cover me'; - $(_.compile('
    {{name}}
    ')); + _.compile('
    {{name}}
    '); _.rootScope.apply(); expect(_.rootScope.context['name']).toEqual('cover me'); expect(_.rootElement.text).toEqual('MyController'); diff --git a/test/directive/ng_repeat_spec.dart b/test/directive/ng_repeat_spec.dart index b4598faa2..29fefb1bb 100644 --- a/test/directive/ng_repeat_spec.dart +++ b/test/directive/ng_repeat_spec.dart @@ -213,17 +213,15 @@ main() { it(r'should error on wrong parsing of ngRepeat', () { - element = $('
    '); expect(() { - $compile(element); + $compile('
    '); }).toThrow("[NgErr7] ngRepeat error! Expected expression in form of '_item_ in _collection_[ track by _id_]' but got 'i dont parse'."); }); it("should throw error when left-hand-side of ngRepeat can't be parsed", () { - element = $('
    '); expect(() { - $compile(element); + $compile('
    '); }).toThrow("[NgErr8] ngRepeat error! '_item_' in '_item_ in _collection_' should be an identifier or '(_key_, _value_)' expression, but got 'i dont parse'."); });