+
+
''');
@@ -86,10 +93,9 @@ main() {
document.querySelector('[on-abc]').dispatchEvent(new Event('abc'));
var shadowRoot = document.querySelector('bar').shadowRoot;
var shadowRootScope = _.getScope(shadowRoot);
- BarComponent ctrl = shadowRootScope.context['ctrl'];
- expect(ctrl.invoked).toEqual(false);
+ expect(shadowRootScope.context.invoked).toEqual(false);
- expect(_.rootScope.context['ctrl']['invoked']).toEqual(true);
+ expect(_.rootScope.context['invoked']).toEqual(true);
}));
});
}
diff --git a/test/core_dom/web_platform_spec.dart b/test/core_dom/web_platform_spec.dart
index 17c96f68c..10964b5dd 100644
--- a/test/core_dom/web_platform_spec.dart
+++ b/test/core_dom/web_platform_spec.dart
@@ -189,7 +189,6 @@ main() {
@Component(
selector: "test-wptc",
- publishAs: "ctrl",
templateUrl: "template.html",
cssUrl: "style.css")
class _WebPlatformTestComponent {
@@ -197,7 +196,6 @@ class _WebPlatformTestComponent {
@Component(
selector: "test-wptca[a]",
- publishAs: "ctrl",
templateUrl: "template.html",
cssUrl: "style.css")
class _WebPlatformTestComponentWithAttribute {
@@ -205,7 +203,6 @@ class _WebPlatformTestComponentWithAttribute {
@Component(
selector: "my-inner",
- publishAs: "ctrl",
templateUrl: "inner-html.html",
cssUrl: "inner-style.css")
class _InnerComponent {
@@ -213,7 +210,6 @@ class _InnerComponent {
@Component(
selector: "my-outer",
- publishAs: "ctrl",
templateUrl: "outer-html.html",
cssUrl: "outer-style.css")
class _OuterComponent {
diff --git a/test/directive/ng_if_spec.dart b/test/directive/ng_if_spec.dart
index 2ad47f030..b23f8f1d9 100644
--- a/test/directive/ng_if_spec.dart
+++ b/test/directive/ng_if_spec.dart
@@ -70,36 +70,57 @@ main() {
}
);
- they('should create a child scope',
+ they('should create and destroy a child scope',
[
// ng-if
'
' +
'
'.trim() +
- ' inside {{setBy}};'.trim() +
+ ' inside {{ctx}};'.trim() +
'
'.trim() +
- '
outside {{setBy}}'.trim() +
+ '
outside {{ctx}}'.trim() +
'
',
// ng-unless
'
' +
'
'.trim() +
- ' inside {{setBy}};'.trim() +
+ ' inside {{ctx}};'.trim() +
'
'.trim() +
- '
outside {{setBy}}'.trim() +
+ '
outside {{ctx}}'.trim() +
'
'],
(html) {
- rootScope.context['setBy'] = 'topLevel';
+ rootScope.context['ctx'] = 'parent';
+
+ var getChildScope = () => rootScope.context['probe'] == null ?
+ null : rootScope.context['probe'].scope;
+
compile(html);
- expect(element).toHaveText('outside topLevel');
+ expect(element).toHaveText('outside parent');
+ expect(getChildScope()).toBeNull();
+
+ rootScope.apply(() {
+ rootScope.context['isVisible'] = true;
+ });
+ // The nested scope uses the parent context
+ expect(element).toHaveText('inside parent;outside parent');
+ expect(element.querySelector('#outside')).toHaveHtml('outside parent');
+ expect(element.querySelector('#inside')).toHaveHtml('inside parent;');
+
+ var childScope1 = getChildScope();
+ expect(childScope1).toBeNotNull();
+ var destroyListener = guinness.createSpy('destroy child scope');
+ var watcher = childScope1.on(ScopeEvent.DESTROY).listen(destroyListener);
+
+ rootScope.apply(() {
+ rootScope.context['isVisible'] = false;
+ });
+ expect(getChildScope()).toBeNull();
+ expect(destroyListener).toHaveBeenCalledOnce();
rootScope.apply(() {
rootScope.context['isVisible'] = true;
});
- expect(element).toHaveText('inside childController;outside topLevel');
- // The value on the parent scope.context['should'] be unchanged.
- expect(rootScope.context['setBy']).toEqual('topLevel');
- expect(element.querySelector('#outside')).toHaveHtml('outside topLevel');
- // A child scope.context['must'] have been created and hold a different value.
- expect(element.querySelector('#inside')).toHaveHtml('inside childController;');
+ var childScope2 = getChildScope();
+ expect(childScope2).toBeNotNull();
+ expect(childScope2).not.toBe(childScope1);
}
);
diff --git a/test/directive/ng_include_spec.dart b/test/directive/ng_include_spec.dart
index b1b793b70..7ff719f3c 100644
--- a/test/directive/ng_include_spec.dart
+++ b/test/directive/ng_include_spec.dart
@@ -13,12 +13,12 @@ main() {
var element = _.compile('
');
- expect(element.innerHtml).toEqual('');
+ expect(element).toHaveText('');
microLeap(); // load the template from cache.
scope.context['name'] = 'Vojta';
scope.apply();
- expect(element.text).toEqual('my name is Vojta');
+ expect(element).toHaveText('my name is Vojta');
}));
it('should fetch template from url using interpolation', async((Scope scope, TemplateCache cache) {
@@ -27,7 +27,7 @@ main() {
var element = _.compile('
');
- expect(element.innerHtml).toEqual('');
+ expect(element).toHaveText('');
scope.context['name'] = 'Vojta';
scope.context['template'] = 'tpl1.html';
@@ -35,15 +35,54 @@ main() {
scope.apply();
microLeap();
scope.apply();
- expect(element.text).toEqual('My name is Vojta');
+ expect(element).toHaveText('My name is Vojta');
scope.context['template'] = 'tpl2.html';
microLeap();
scope.apply();
microLeap();
scope.apply();
- expect(element.text).toEqual('I am Vojta');
+ expect(element).toHaveText('I am Vojta');
}));
+ it('should create and destroy a child scope', async((Scope scope, TemplateCache cache) {
+ cache.put('tpl.html', new HttpResponse(200, '
include
'));
+
+ var getChildScope = () => scope.context['probe'] == null ?
+ null : scope.context['probe'].scope;
+
+ var element = _.compile('
');
+
+ expect(element).toHaveText('');
+ expect(getChildScope()).toBeNull();
+
+ scope.context['template'] = 'tpl.html';
+ microLeap();
+ scope.apply();
+ microLeap();
+ scope.apply();
+ expect(element).toHaveText('include');
+ var childScope1 = getChildScope();
+ expect(childScope1).toBeNotNull();
+ var destroyListener = guinness.createSpy('destroy child scope');
+ var watcher = childScope1.on(ScopeEvent.DESTROY).listen(destroyListener);
+
+ scope.context['template'] = null;
+ microLeap();
+ scope.apply();
+ expect(element).toHaveText('');
+ expect(getChildScope()).toBeNull();
+ expect(destroyListener).toHaveBeenCalledOnce();
+
+ scope.context['template'] = 'tpl.html';
+ microLeap();
+ scope.apply();
+ microLeap();
+ scope.apply();
+ expect(element).toHaveText('include');
+ var childScope2 = getChildScope();
+ expect(childScope2).toBeNotNull();
+ expect(childScope2).not.toBe(childScope1);
+ }));
});
}
diff --git a/test/directive/ng_model_spec.dart b/test/directive/ng_model_spec.dart
index 1c2a3ae30..2f3da0db4 100644
--- a/test/directive/ng_model_spec.dart
+++ b/test/directive/ng_model_spec.dart
@@ -1668,8 +1668,7 @@ void main() {
@Component(
selector: 'no-love',
- template: '
',
- publishAs: 'ctrl')
+ template: '
')
class ComponentWithNoLove {
}
diff --git a/test/directive/ng_repeat_spec.dart b/test/directive/ng_repeat_spec.dart
index a0a61f5ee..78931a9f8 100644
--- a/test/directive/ng_repeat_spec.dart
+++ b/test/directive/ng_repeat_spec.dart
@@ -404,9 +404,7 @@ main() {
it('should not error when the first watched item is removed', () {
element = compile(
'
');
scope.context['items'] = ['misko', 'shyam', 'frodo'];
scope.apply();
@@ -419,9 +417,7 @@ main() {
it('should not error when the last watched item is removed', () {
element = compile(
'
');
scope.context['items'] = ['misko', 'shyam', 'frodo'];
scope.apply();
@@ -434,15 +430,12 @@ main() {
it('should not error when multiple watched items are removed at the same time', () {
element = compile(
'
');
scope.context['items'] = ['misko', 'shyam', 'frodo', 'igor'];
scope.apply();
expect(element.children.length).toEqual(4);
- scope.context['items'].remove('shyam');
- scope.context['items'].remove('frodo');
+ scope.context['items']..remove('shyam')..remove('frodo');
scope.apply();
expect(element.children.length).toEqual(2);
});
@@ -529,13 +522,13 @@ main() {
it('should correctly handle detached state', () {
scope.context['items'] = [1];
- var parentScope = scope.createChild(new PrototypeMap(scope.context));
+ var childScope = scope.createChild(scope.context);
element = compile(
'
', parentScope);
+ '', childScope);
- parentScope.destroy();
+ childScope.destroy();
expect(scope.apply).not.toThrow();
});
diff --git a/test/directive/ng_switch_spec.dart b/test/directive/ng_switch_spec.dart
index 2c26666ca..2ab47c728 100644
--- a/test/directive/ng_switch_spec.dart
+++ b/test/directive/ng_switch_spec.dart
@@ -174,7 +174,7 @@ void main() {
_.rootScope.apply();
var getChildScope = () => _.rootScope.context['probe'] == null ?
- null : _.rootScope.context['probe'].scope;
+ null : _.rootScope.context['probe'].scope;
expect(getChildScope()).toBeNull();
diff --git a/test/io/expression_extractor_spec.dart b/test/io/expression_extractor_spec.dart
index 6a2711270..9b1e12cc2 100644
--- a/test/io/expression_extractor_spec.dart
+++ b/test/io/expression_extractor_spec.dart
@@ -33,19 +33,15 @@ void main() {
var expressions = _extractExpressions('test/io/test_files/main.dart');
expect(expressions, unorderedEquals([
- 'ctrl.expr',
- 'ctrl.anotherExpression',
- 'ctrl.callback',
- 'ctrl.twoWayStuff',
'attr',
'expr',
'anotherExpression',
'callback',
'twoWayStuff',
'exported + expression',
- 'ctrl.inline.template.expression',
+ 'inline.template.expression',
'ngIfCondition',
- 'ctrl.if'
+ 'if'
]));
});
diff --git a/test/io/test_files/main.dart b/test/io/test_files/main.dart
index cd263cdfd..094684265 100644
--- a/test/io/test_files/main.dart
+++ b/test/io/test_files/main.dart
@@ -16,7 +16,7 @@ class NgIfDirective {
'attr': '@attr',
'expr': '=>expr'
},
- template: '
{{ctrl.inline.template.expression}}
',
+ template: '
{{inline.template.expression}}
',
exportExpressionAttrs: const ['exported-attr'],
exportExpressions: const ['exported + expression'])
class MyComponent {
diff --git a/test/io/test_files/main.html b/test/io/test_files/main.html
index 95ecc8ad0..41b1ff188 100644
--- a/test/io/test_files/main.html
+++ b/test/io/test_files/main.html
@@ -1,16 +1,15 @@
-
+
+ attr="attr2" expr="expr2"
+ another-expression="anotherExpression2"
+ callback="callback2"
+ two-way-stuff="twoWayStuff2">
-
-
+
\ No newline at end of file
diff --git a/test/routing/ng_view_spec.dart b/test/routing/ng_view_spec.dart
index 34bffa8f8..c0fd88623 100644
--- a/test/routing/ng_view_spec.dart
+++ b/test/routing/ng_view_spec.dart
@@ -20,28 +20,26 @@ main() => describe('ngView', () {
_ = tb;
router = _router;
- templates.put('foo.html', new HttpResponse(200,
- '
Foo
'));
- templates.put('bar.html', new HttpResponse(200,
- '
Bar
'));
+ templates.put('foo.html', new HttpResponse(200, '
Foo
'));
+ templates.put('bar.html', new HttpResponse(200, '
Bar
'));
});
it('should switch template', async(() {
Element root = _.compile('
');
- expect(root.text).toEqual('');
+ expect(root).toHaveText('');
router.route('/foo');
microLeap();
- expect(root.text).toEqual('Foo');
+ expect(root).toHaveText('Foo');
router.route('/bar');
microLeap();
- expect(root.text).toEqual('Bar');
+ expect(root).toHaveText('Bar');
router.route('/foo');
microLeap();
- expect(root.text).toEqual('Foo');
+ expect(root).toHaveText('Foo');
}));
it('should expose NgView as RouteProvider', async(() {
@@ -62,25 +60,50 @@ main() => describe('ngView', () {
router.route('/foo');
microLeap();
Element root = _.compile('
');
- expect(root.text).toEqual('');
+ expect(root).toHaveText('');
_.rootScope.apply();
microLeap();
- expect(root.text).toEqual('Foo');
+ expect(root).toHaveText('Foo');
}));
it('should clear template when route is deactivated', async(() {
Element root = _.compile('
');
- expect(root.text).toEqual('');
+ expect(root).toHaveText('');
router.route('/foo');
microLeap();
- expect(root.text).toEqual('Foo');
+ expect(root).toHaveText('Foo');
router.route('/baz'); // route without a template
microLeap();
- expect(root.text).toEqual('');
+ expect(root).toHaveText('');
+ }));
+
+ it('should create and destroy a child scope', async((RootScope scope) {
+ Element root = _.compile('
');
+
+ var getChildScope = () => scope.context['p'] == null ?
+ null : scope.context['p'].scope;
+
+ expect(root).toHaveText('');
+ expect(getChildScope()).toBeNull();
+
+ router.route('/foo');
+ microLeap();
+ expect(root).toHaveText('Foo');
+ var childScope1 = getChildScope();
+ expect(childScope1).toBeNotNull();
+ var destroyListener = guinness.createSpy('destroy child scope');
+ var watcher = childScope1.on(ScopeEvent.DESTROY).listen(destroyListener);
+
+ router.route('/baz');
+ microLeap();
+ expect(root).toHaveText('');
+ expect(destroyListener).toHaveBeenCalledOnce();
+ var childScope2 = getChildScope();
+ expect(childScope2).toBeNull();
}));
});
@@ -116,25 +139,25 @@ main() => describe('ngView', () {
it('should switch nested templates', async(() {
Element root = _.compile('
');
microLeap(); _.rootScope.apply(); microLeap();
- expect(root.text).toEqual('');
+ expect(root).toHaveText('');
router.route('/library/all');
microLeap(); _.rootScope.apply(); microLeap();
- expect(root.text).toEqual('LibraryBooks');
+ expect(root).toHaveText('LibraryBooks');
router.route('/library/1234');
microLeap(); _.rootScope.apply(); microLeap();
- expect(root.text).toEqual('LibraryBook 1234');
+ expect(root).toHaveText('LibraryBook 1234');
// nothing should change here
router.route('/library/1234/overview');
microLeap(); _.rootScope.apply(); microLeap();
- expect(root.text).toEqual('LibraryBook 1234');
+ expect(root).toHaveText('LibraryBook 1234');
// nothing should change here
router.route('/library/1234/read');
microLeap(); _.rootScope.apply(); microLeap();
- expect(root.text).toEqual('LibraryRead Book 1234');
+ expect(root).toHaveText('LibraryRead Book 1234');
}));
it('should not attempt to destroy and already destroyed childscope', async(() {
@@ -182,11 +205,11 @@ main() => describe('ngView', () {
it('should switch inline templates', async(() {
Element root = _.compile('
');
- expect(root.text).toEqual('');
+ expect(root).toHaveText('');
router.route('/foo');
microLeap();
- expect(root.text).toEqual('Hello');
+ expect(root).toHaveText('Hello');
}));
});
});
diff --git a/test/tools/html_extractor_spec.dart b/test/tools/html_extractor_spec.dart
index 253059d11..012eb1529 100644
--- a/test/tools/html_extractor_spec.dart
+++ b/test/tools/html_extractor_spec.dart
@@ -13,40 +13,40 @@ void main() {
it('should extract text mustache expressions', () {
var ioService = new MockIoService({
'foo.html': r'''
-
foo {{ctrl.bar}} baz {{aux}}
+
foo {{bar}} baz {{aux}}
'''
});
var extractor = new HtmlExpressionExtractor([]);
extractor.crawl('/', ioService);
expect(extractor.expressions.toList()..sort(),
- equals(['aux', 'ctrl.bar']));
+ equals(['aux', 'bar']));
});
it('should extract attribute mustache expressions', () {
var ioService = new MockIoService({
'foo.html': r'''
-
+
'''
});
var extractor = new HtmlExpressionExtractor([]);
extractor.crawl('/', ioService);
expect(extractor.expressions.toList()..sort(),
- equals(['aux', 'ctrl.bar']));
+ equals(['aux', 'bar']));
});
it('should extract ng-repeat expressions', () {
var ioService = new MockIoService({
'foo.html': r'''
-
+
'''
});
var extractor = new HtmlExpressionExtractor([]);
extractor.crawl('/', ioService);
expect(extractor.expressions.toList()..sort(),
- equals(['ctrl.bar']));
+ equals(['bar']));
});
it('should extract expressions provided in the directive info', () {
@@ -61,30 +61,30 @@ void main() {
});
it('should extract expressions from expression attributes', () {
- var ioService = new MockIoService({'foo.html': r'
'});
+ var ioService = new MockIoService({
+ 'foo.html': r'
'
+ });
var extractor = new HtmlExpressionExtractor([
new DirectiveInfo('foo', ['bar'])
]);
extractor.crawl('/', ioService);
- expect(extractor.expressions.toList()).toEqual(['ctrl.baz']);
+ expect(extractor.expressions.toList()).toEqual(['baz']);
});
it('should extract expressions from expression attributes for camelCased attributes', () {
- var ioService = new MockIoService({'foo.html': r'
'});
+ var ioService = new MockIoService({'foo.html': r'
'});
var extractor = new HtmlExpressionExtractor([
new DirectiveInfo('foo', ['fooBar'])
]);
extractor.crawl('/', ioService);
- expect(extractor.expressions.toList()).toEqual(['ctrl.baz']);
+ expect(extractor.expressions.toList()).toEqual(['baz']);
});
it('should ignore ng-repeat while extracting attribute expressions', () {
var ioService = new MockIoService({
- 'foo.html': r'''
-
- '''
+ 'foo.html': r'
'
});
var extractor = new HtmlExpressionExtractor([
@@ -93,7 +93,7 @@ void main() {
extractor.crawl('/', ioService);
// Basically we don't want to extract "foo in ctrl.bar".
expect(extractor.expressions.toList()..sort(),
- equals(['ctrl.bar']));
+ equals(['bar']));
});
});
}
diff --git a/test_e2e/animation_ng_repeat_spec.dart b/test_e2e/animation_ng_repeat_spec.dart
index 51064160b..709ea1af7 100644
--- a/test_e2e/animation_ng_repeat_spec.dart
+++ b/test_e2e/animation_ng_repeat_spec.dart
@@ -3,7 +3,7 @@ part of angular.example.animation_spec;
class NgRepeatAppState extends AppState {
var addBtn = element(by.buttonText("Add Thing"));
var removeBtn = element(by.buttonText("Remove Thing"));
- var rows = element.all(by.repeater("outer in ctrl.items"));
+ var rows = element.all(by.repeater("outer in items"));
var thingId = 0; // monotonically increasing.
var things = [];
diff --git a/test_e2e/todo_spec.dart b/test_e2e/todo_spec.dart
index bc60086e9..67c7b9f88 100644
--- a/test_e2e/todo_spec.dart
+++ b/test_e2e/todo_spec.dart
@@ -4,16 +4,16 @@ import 'package:protractor/protractor_api.dart';
class AppState {
- var items = element.all(by.repeater('item in todo.items'));
- var remaining = element(by.binding('todo.remaining'));
- var total = element(by.binding('todo.items.length'));
+ var items = element.all(by.repeater('item in items'));
+ var remaining = element(by.binding('remaining'));
+ var total = element(by.binding('items.length'));
var markAllDoneBtn = element(by.buttonText("mark all done"));
var archiveDoneBtn = element(by.buttonText("archive done"));
var addBtn = element(by.buttonText("add"));
var clearBtn = element(by.buttonText("clear"));
- var newItemInput = element(by.model("todo.newItem.text"));
+ var newItemInput = element(by.model("newItem.text"));
get newItemText => newItemInput.getAttribute('value');
todo(i) => items.get(i).getText();
@@ -44,7 +44,7 @@ class AppState {
expect(clearBtn.isEnabled()).toEqual(text.length > 0);
// input field and model value should contain the typed text.
expect(newItemText).toEqual(text);
- expect(newItemInput.evaluate('todo.newItem.text')).toEqual(text);
+ expect(newItemInput.evaluate('newItem.text')).toEqual(text);
}
}