refactor(reflection): improved error message
This commit is contained in:
parent
c54f5e0ba2
commit
62b1a08f06
|
@ -1,6 +1,7 @@
|
|||
library reflection.reflection_capabilities;
|
||||
|
||||
import 'reflection.dart';
|
||||
import 'package:angular2/src/facade/lang.dart';
|
||||
import 'types.dart';
|
||||
import 'dart:mirrors';
|
||||
|
||||
|
@ -45,7 +46,7 @@ class ReflectionCapabilities {
|
|||
create(name, [a1, a2, a3, a4, a5, a6, a7, a8, a9, a10]).reflectee;
|
||||
}
|
||||
|
||||
throw "Factory cannot take more than 10 arguments";
|
||||
throw "Cannot create a factory for '${stringify(type)}' because its constructor has more than 10 arguments";
|
||||
}
|
||||
|
||||
List<List> parameters(typeOrFunc) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import {Type, isPresent, global} from 'angular2/src/facade/lang';
|
||||
import {Type, isPresent, global, stringify} from 'angular2/src/facade/lang';
|
||||
import {List, ListWrapper} from 'angular2/src/facade/collection';
|
||||
import {GetterFn, SetterFn, MethodFn} from './types';
|
||||
|
||||
|
@ -39,7 +39,8 @@ export class ReflectionCapabilities {
|
|||
};
|
||||
};
|
||||
|
||||
throw new Error("Factory cannot take more than 10 arguments");
|
||||
throw new Error(
|
||||
`Cannot create a factory for '${stringify(t)}' because its constructor has more than 10 arguments`);
|
||||
}
|
||||
|
||||
_zipTypesAndAnnotaions(paramTypes, paramAnnotations): List<List<any>> {
|
||||
|
|
|
@ -31,6 +31,18 @@ export function main() {
|
|||
}
|
||||
|
||||
describe('reflection capabilities', () => {
|
||||
describe("factory", () => {
|
||||
it("should create a factory for a type", () => {
|
||||
var f = rc.factory(ClassWithField);
|
||||
expect(f("value").field).toEqual("value");
|
||||
});
|
||||
|
||||
it("should throw when a constructor has more than 10 args", () => {
|
||||
expect(() => rc.factory(ClassWith11Fields)).toThrowError(
|
||||
new RegExp(`has more than 10 arguments`));
|
||||
});
|
||||
});
|
||||
|
||||
it('can read out class annotations through annotations key', () => {
|
||||
assertTestClassAnnotations(rc.annotations(TestClass));
|
||||
});
|
||||
|
@ -115,6 +127,17 @@ class TestClassTypesOnly {
|
|||
constructor(a: P1, b: P2) {}
|
||||
}
|
||||
|
||||
class ClassWithField {
|
||||
field;
|
||||
constructor(field) {
|
||||
this.field = field;
|
||||
}
|
||||
}
|
||||
class ClassWith11Fields {
|
||||
constructor(a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10) {
|
||||
}
|
||||
}
|
||||
|
||||
// Mocking the data stored in global.Reflect as if TS was compiling TestClass above.
|
||||
var mockDataForTestClassTypesOnly = {
|
||||
'annotations': null,
|
||||
|
|
Loading…
Reference in New Issue