feat(di): support type literals in DI
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
/// This file contains tests that make sense only in Dart
|
||||
library angular2.test.di.integration_dart_spec;
|
||||
|
||||
import 'package:angular2/angular2.dart';
|
||||
import 'package:angular2/di.dart';
|
||||
import 'package:angular2/src/test_lib/test_bed.dart';
|
||||
import 'package:angular2/test_lib.dart';
|
||||
|
||||
main() {
|
||||
describe('TypeLiteral', () {
|
||||
it('should publish via injectables',
|
||||
inject([TestBed, AsyncTestCompleter], (tb, async) {
|
||||
tb.overrideView(Dummy, new View(
|
||||
template: '<type-literal-component></type-literal-component>',
|
||||
directives: [TypeLiteralComponent]
|
||||
));
|
||||
|
||||
tb.createView(Dummy).then((view) {
|
||||
view.detectChanges();
|
||||
expect(view.rootNodes).toHaveText('[Hello, World]');
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
@Component(selector: 'dummy')
|
||||
class Dummy {}
|
||||
|
||||
@Component(
|
||||
selector: 'type-literal-component',
|
||||
injectables: const [
|
||||
const Binding(
|
||||
const TypeLiteral<List<String>>(),
|
||||
toValue: const <String>['Hello', 'World'])
|
||||
]
|
||||
)
|
||||
@View(
|
||||
template: '{{list}}'
|
||||
)
|
||||
class TypeLiteralComponent {
|
||||
final List<String> list;
|
||||
|
||||
TypeLiteralComponent(this.list);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/// This file contains tests that make sense only in Dart
|
||||
library angular2.test.di.injector_dart_spec;
|
||||
|
||||
import 'package:angular2/test_lib.dart';
|
||||
import 'package:angular2/di.dart';
|
||||
|
||||
main() {
|
||||
describe('Injector', () {
|
||||
it('should support TypeLiteral', () {
|
||||
var i = Injector.resolveAndCreate([
|
||||
bind(new TypeLiteral<List<int>>()).toValue([1, 2, 3]),
|
||||
Foo,
|
||||
]);
|
||||
expect(i.get(Foo).value).toEqual([1, 2, 3]);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
class Foo {
|
||||
final List<int> value;
|
||||
Foo(this.value);
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/// This file contains tests that make sense only in Dart
|
||||
library angular2.test.di.key_dart_spec;
|
||||
|
||||
import 'package:angular2/test_lib.dart';
|
||||
import 'package:angular2/di.dart';
|
||||
|
||||
main() {
|
||||
describe('TypeLiteral', () {
|
||||
it('contains type', () {
|
||||
var t = new TypeLiteral<List<int>>();
|
||||
expect('${t.type}').toEqual('List<int>');
|
||||
});
|
||||
|
||||
it('can be a constant', () {
|
||||
var a = const TypeLiteral<List<int>>();
|
||||
var b = const TypeLiteral<List<int>>();
|
||||
expect(identical(a, b)).toBe(true);
|
||||
});
|
||||
|
||||
it('can be unique', () {
|
||||
var a = const TypeLiteral<List<String>>();
|
||||
var b = const TypeLiteral<List<int>>();
|
||||
expect(identical(a, b)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Key', () {
|
||||
KeyRegistry registry;
|
||||
|
||||
beforeEach(() {
|
||||
registry = new KeyRegistry();
|
||||
});
|
||||
|
||||
it('understands TypeLiteral', () {
|
||||
var k = registry.get(const TypeLiteral<List<int>>());
|
||||
expect('${k.token}').toEqual('List<int>');
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user