style(dart): Format Dart source with dart_style 0.1.8
This commit is contained in:
@ -4,108 +4,127 @@ import 'package:angular2/test_lib.dart';
|
||||
import 'package:angular2/angular2.dart';
|
||||
import 'package:angular2/src/core/compiler/element_injector.dart';
|
||||
|
||||
|
||||
main() {
|
||||
describe('Create DirectiveMetadata', () {
|
||||
describe('lifecycle', () {
|
||||
metadata(type, annotation) => DirectiveBinding.createFromType(type, annotation).metadata;
|
||||
|
||||
metadata(type, annotation) =>
|
||||
DirectiveBinding.createFromType(type, annotation).metadata;
|
||||
|
||||
describe("onChange", () {
|
||||
it("should be true when the directive implements OnChange", () {
|
||||
expect(metadata(DirectiveImplementingOnChange, new Directive()).callOnChange).toBe(true);
|
||||
expect(metadata(
|
||||
DirectiveImplementingOnChange, new Directive()).callOnChange)
|
||||
.toBe(true);
|
||||
});
|
||||
|
||||
it("should be true when the lifecycle includes onChange", () {
|
||||
expect(metadata(DirectiveNoHooks, new Directive(lifecycle: [onChange])).callOnChange).toBe(true);
|
||||
expect(metadata(DirectiveNoHooks,
|
||||
new Directive(lifecycle: [onChange])).callOnChange).toBe(true);
|
||||
});
|
||||
|
||||
it("should be false otherwise", () {
|
||||
expect(metadata(DirectiveNoHooks, new Directive()).callOnChange).toBe(false);
|
||||
expect(metadata(DirectiveNoHooks, new Directive()).callOnChange)
|
||||
.toBe(false);
|
||||
});
|
||||
|
||||
it("should be false when empty lifecycle", () {
|
||||
expect(metadata(DirectiveImplementingOnChange, new Directive(lifecycle: [])).callOnChange).toBe(false);
|
||||
expect(metadata(DirectiveImplementingOnChange,
|
||||
new Directive(lifecycle: [])).callOnChange).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("onDestroy", () {
|
||||
it("should be true when the directive implements OnDestroy", () {
|
||||
expect(metadata(DirectiveImplementingOnDestroy, new Directive()).callOnDestroy).toBe(true);
|
||||
expect(metadata(DirectiveImplementingOnDestroy,
|
||||
new Directive()).callOnDestroy).toBe(true);
|
||||
});
|
||||
|
||||
it("should be true when the lifecycle includes onDestroy", () {
|
||||
expect(metadata(DirectiveNoHooks, new Directive(lifecycle: [onDestroy])).callOnDestroy).toBe(true);
|
||||
expect(metadata(DirectiveNoHooks,
|
||||
new Directive(lifecycle: [onDestroy])).callOnDestroy).toBe(true);
|
||||
});
|
||||
|
||||
it("should be false otherwise", () {
|
||||
expect(metadata(DirectiveNoHooks, new Directive()).callOnDestroy).toBe(false);
|
||||
expect(metadata(DirectiveNoHooks, new Directive()).callOnDestroy)
|
||||
.toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("onCheck", () {
|
||||
it("should be true when the directive implements OnCheck", () {
|
||||
expect(metadata(DirectiveImplementingOnCheck, new Directive()).callOnCheck).toBe(true);
|
||||
expect(metadata(
|
||||
DirectiveImplementingOnCheck, new Directive()).callOnCheck)
|
||||
.toBe(true);
|
||||
});
|
||||
|
||||
it("should be true when the lifecycle includes onCheck", () {
|
||||
expect(metadata(DirectiveNoHooks, new Directive(lifecycle: [onCheck])).callOnCheck).toBe(true);
|
||||
expect(metadata(DirectiveNoHooks,
|
||||
new Directive(lifecycle: [onCheck])).callOnCheck).toBe(true);
|
||||
});
|
||||
|
||||
it("should be false otherwise", () {
|
||||
expect(metadata(DirectiveNoHooks, new Directive()).callOnCheck).toBe(false);
|
||||
expect(metadata(DirectiveNoHooks, new Directive()).callOnCheck)
|
||||
.toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("onInit", () {
|
||||
it("should be true when the directive implements OnInit", () {
|
||||
expect(metadata(DirectiveImplementingOnInit, new Directive()).callOnInit).toBe(true);
|
||||
expect(metadata(
|
||||
DirectiveImplementingOnInit, new Directive()).callOnInit)
|
||||
.toBe(true);
|
||||
});
|
||||
|
||||
it("should be true when the lifecycle includes onInit", () {
|
||||
expect(metadata(DirectiveNoHooks, new Directive(lifecycle: [onInit])).callOnInit).toBe(true);
|
||||
expect(metadata(DirectiveNoHooks,
|
||||
new Directive(lifecycle: [onInit])).callOnInit).toBe(true);
|
||||
});
|
||||
|
||||
it("should be false otherwise", () {
|
||||
expect(metadata(DirectiveNoHooks, new Directive()).callOnInit).toBe(false);
|
||||
expect(metadata(DirectiveNoHooks, new Directive()).callOnInit)
|
||||
.toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("onAllChangesDone", () {
|
||||
it("should be true when the directive implements OnAllChangesDone", () {
|
||||
expect(metadata(DirectiveImplementingOnAllChangesDone, new Directive()).callOnAllChangesDone).toBe(true);
|
||||
expect(metadata(DirectiveImplementingOnAllChangesDone,
|
||||
new Directive()).callOnAllChangesDone).toBe(true);
|
||||
});
|
||||
|
||||
it("should be true when the lifecycle includes onAllChangesDone", () {
|
||||
expect(metadata(DirectiveNoHooks, new Directive(lifecycle: [onAllChangesDone])).callOnAllChangesDone).toBe(true);
|
||||
expect(metadata(DirectiveNoHooks, new Directive(
|
||||
lifecycle: [onAllChangesDone])).callOnAllChangesDone).toBe(true);
|
||||
});
|
||||
|
||||
it("should be false otherwise", () {
|
||||
expect(metadata(DirectiveNoHooks, new Directive()).callOnAllChangesDone).toBe(false);
|
||||
expect(metadata(
|
||||
DirectiveNoHooks, new Directive()).callOnAllChangesDone)
|
||||
.toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
class DirectiveNoHooks {
|
||||
}
|
||||
class DirectiveNoHooks {}
|
||||
|
||||
class DirectiveImplementingOnChange implements OnChange {
|
||||
onChange(_){}
|
||||
onChange(_) {}
|
||||
}
|
||||
|
||||
class DirectiveImplementingOnCheck implements OnCheck {
|
||||
onCheck(){}
|
||||
onCheck() {}
|
||||
}
|
||||
|
||||
class DirectiveImplementingOnInit implements OnInit {
|
||||
onInit(){}
|
||||
onInit() {}
|
||||
}
|
||||
|
||||
class DirectiveImplementingOnDestroy implements OnDestroy {
|
||||
onDestroy(){}
|
||||
onDestroy() {}
|
||||
}
|
||||
|
||||
class DirectiveImplementingOnAllChangesDone implements OnAllChangesDone {
|
||||
onAllChangesDone(){}
|
||||
}
|
||||
onAllChangesDone() {}
|
||||
}
|
||||
|
@ -6,12 +6,18 @@ import 'package:angular2/di.dart';
|
||||
import 'package:angular2/src/test_lib/test_bed.dart';
|
||||
import 'package:angular2/test_lib.dart';
|
||||
|
||||
class MockException implements Error { var message; var stackTrace; }
|
||||
class NonError { var message; }
|
||||
class MockException implements Error {
|
||||
var message;
|
||||
var stackTrace;
|
||||
}
|
||||
class NonError {
|
||||
var message;
|
||||
}
|
||||
|
||||
void functionThatThrows() {
|
||||
try { throw new MockException(); }
|
||||
catch(e, stack) {
|
||||
try {
|
||||
throw new MockException();
|
||||
} catch (e, stack) {
|
||||
// If we lose the stack trace the message will no longer match
|
||||
// the first line in the stack
|
||||
e.message = stack.toString().split('\n')[0];
|
||||
@ -21,8 +27,9 @@ void functionThatThrows() {
|
||||
}
|
||||
|
||||
void functionThatThrowsNonError() {
|
||||
try { throw new NonError(); }
|
||||
catch(e, stack) {
|
||||
try {
|
||||
throw new NonError();
|
||||
} catch (e, stack) {
|
||||
// If we lose the stack trace the message will no longer match
|
||||
// the first line in the stack
|
||||
e.message = stack.toString().split('\n')[0];
|
||||
@ -32,12 +39,13 @@ void functionThatThrowsNonError() {
|
||||
|
||||
main() {
|
||||
describe('TypeLiteral', () {
|
||||
it('should publish via appInjector',
|
||||
inject([TestBed, AsyncTestCompleter], (tb, async) {
|
||||
it('should publish via appInjector', inject([
|
||||
TestBed,
|
||||
AsyncTestCompleter
|
||||
], (tb, async) {
|
||||
tb.overrideView(Dummy, new View(
|
||||
template: '<type-literal-component></type-literal-component>',
|
||||
directives: [TypeLiteralComponent]
|
||||
));
|
||||
template: '<type-literal-component></type-literal-component>',
|
||||
directives: [TypeLiteralComponent]));
|
||||
|
||||
tb.createView(Dummy).then((view) {
|
||||
view.detectChanges();
|
||||
@ -48,12 +56,13 @@ main() {
|
||||
});
|
||||
|
||||
describe('Error handling', () {
|
||||
it('should preserve Error stack traces thrown from components',
|
||||
inject([TestBed, AsyncTestCompleter], (tb, async) {
|
||||
it('should preserve Error stack traces thrown from components', inject([
|
||||
TestBed,
|
||||
AsyncTestCompleter
|
||||
], (tb, async) {
|
||||
tb.overrideView(Dummy, new View(
|
||||
template: '<throwing-component></throwing-component>',
|
||||
directives: [ThrowingComponent]
|
||||
));
|
||||
template: '<throwing-component></throwing-component>',
|
||||
directives: [ThrowingComponent]));
|
||||
|
||||
tb.createView(Dummy).catchError((e, stack) {
|
||||
expect(stack.toString().split('\n')[0]).toEqual(e.message);
|
||||
@ -61,12 +70,13 @@ main() {
|
||||
});
|
||||
}));
|
||||
|
||||
it('should preserve non-Error stack traces thrown from components',
|
||||
inject([TestBed, AsyncTestCompleter], (tb, async) {
|
||||
it('should preserve non-Error stack traces thrown from components', inject([
|
||||
TestBed,
|
||||
AsyncTestCompleter
|
||||
], (tb, async) {
|
||||
tb.overrideView(Dummy, new View(
|
||||
template: '<throwing-component2></throwing-component2>',
|
||||
directives: [ThrowingComponent2]
|
||||
));
|
||||
template: '<throwing-component2></throwing-component2>',
|
||||
directives: [ThrowingComponent2]));
|
||||
|
||||
tb.createView(Dummy).catchError((e, stack) {
|
||||
expect(stack.toString().split('\n')[0]).toEqual(e.message);
|
||||
@ -76,12 +86,13 @@ main() {
|
||||
});
|
||||
|
||||
describe('Property access', () {
|
||||
it('should distinguish between map and property access',
|
||||
inject([TestBed, AsyncTestCompleter], (tb, async) {
|
||||
it('should distinguish between map and property access', inject([
|
||||
TestBed,
|
||||
AsyncTestCompleter
|
||||
], (tb, async) {
|
||||
tb.overrideView(Dummy, new View(
|
||||
template: '<property-access></property-access>',
|
||||
directives: [PropertyAccess]
|
||||
));
|
||||
template: '<property-access></property-access>',
|
||||
directives: [PropertyAccess]));
|
||||
|
||||
tb.createView(Dummy).then((view) {
|
||||
view.detectChanges();
|
||||
@ -90,12 +101,13 @@ main() {
|
||||
});
|
||||
}));
|
||||
|
||||
it('should not fallback on map access if property missing',
|
||||
inject([TestBed, AsyncTestCompleter], (tb, async) {
|
||||
it('should not fallback on map access if property missing', inject([
|
||||
TestBed,
|
||||
AsyncTestCompleter
|
||||
], (tb, async) {
|
||||
tb.overrideView(Dummy, new View(
|
||||
template: '<no-property-access></no-property-access>',
|
||||
directives: [NoPropertyAccess]
|
||||
));
|
||||
template: '<no-property-access></no-property-access>',
|
||||
directives: [NoPropertyAccess]));
|
||||
|
||||
tb.createView(Dummy).then((view) {
|
||||
expect(() => view.detectChanges())
|
||||
@ -106,12 +118,13 @@ main() {
|
||||
});
|
||||
|
||||
describe('OnChange', () {
|
||||
it('should be notified of changes',
|
||||
inject([TestBed, AsyncTestCompleter], (tb, async) {
|
||||
it('should be notified of changes', inject([
|
||||
TestBed,
|
||||
AsyncTestCompleter
|
||||
], (tb, async) {
|
||||
tb.overrideView(Dummy, new View(
|
||||
template: '''<on-change [prop]="'hello'"></on-change>''',
|
||||
directives: [OnChangeComponent]
|
||||
));
|
||||
template: '''<on-change [prop]="'hello'"></on-change>''',
|
||||
directives: [OnChangeComponent]));
|
||||
|
||||
tb.createView(Dummy).then((view) {
|
||||
view.detectChanges();
|
||||
@ -128,25 +141,19 @@ main() {
|
||||
class Dummy {}
|
||||
|
||||
@Component(
|
||||
selector: 'type-literal-component',
|
||||
appInjector: const [
|
||||
const Binding(
|
||||
const TypeLiteral<List<String>>(),
|
||||
toValue: const <String>['Hello', 'World'])
|
||||
]
|
||||
)
|
||||
@View(
|
||||
template: '{{list}}'
|
||||
)
|
||||
selector: 'type-literal-component',
|
||||
appInjector: const [
|
||||
const Binding(const TypeLiteral<List<String>>(),
|
||||
toValue: const <String>['Hello', 'World'])
|
||||
])
|
||||
@View(template: '{{list}}')
|
||||
class TypeLiteralComponent {
|
||||
final List<String> list;
|
||||
|
||||
TypeLiteralComponent(this.list);
|
||||
}
|
||||
|
||||
@Component(
|
||||
selector: 'throwing-component'
|
||||
)
|
||||
@Component(selector: 'throwing-component')
|
||||
@View(template: '')
|
||||
class ThrowingComponent {
|
||||
ThrowingComponent() {
|
||||
@ -154,9 +161,7 @@ class ThrowingComponent {
|
||||
}
|
||||
}
|
||||
|
||||
@Component(
|
||||
selector: 'throwing-component2'
|
||||
)
|
||||
@Component(selector: 'throwing-component2')
|
||||
@View(template: '')
|
||||
class ThrowingComponent2 {
|
||||
ThrowingComponent2() {
|
||||
@ -168,7 +173,7 @@ class ThrowingComponent2 {
|
||||
class PropModel implements Map {
|
||||
final String foo = 'foo-prop';
|
||||
|
||||
operator[](_) => 'foo-map';
|
||||
operator [](_) => 'foo-map';
|
||||
|
||||
noSuchMethod(_) {
|
||||
throw 'property not found';
|
||||
@ -187,12 +192,9 @@ class NoPropertyAccess {
|
||||
final model = new PropModel();
|
||||
}
|
||||
|
||||
@Component(
|
||||
selector: 'on-change',
|
||||
// TODO: needed because of https://github.com/angular/angular/issues/2120
|
||||
lifecycle: const [onChange],
|
||||
properties: const ['prop']
|
||||
)
|
||||
@Component(selector: 'on-change',
|
||||
// TODO: needed because of https://github.com/angular/angular/issues/2120
|
||||
lifecycle: const [onChange], properties: const ['prop'])
|
||||
@View(template: '')
|
||||
class OnChangeComponent implements OnChange {
|
||||
Map changes;
|
||||
|
Reference in New Issue
Block a user