fix(ViewLoader): provide componentId in missing template / templateUrl errors
Befor this change it wasn't clear which component is faulty
This commit is contained in:
parent
d853d19dd7
commit
3871f89119
|
@ -36,7 +36,7 @@ export class ViewLoader {
|
||||||
load(viewDef: ViewDefinition): Promise<TemplateAndStyles> {
|
load(viewDef: ViewDefinition): Promise<TemplateAndStyles> {
|
||||||
var r = wtfStartTimeRange('ViewLoader#load()', stringify(viewDef.componentId));
|
var r = wtfStartTimeRange('ViewLoader#load()', stringify(viewDef.componentId));
|
||||||
let tplAndStyles: List<Promise<TemplateAndStyles>| Promise<string>| string> =
|
let tplAndStyles: List<Promise<TemplateAndStyles>| Promise<string>| string> =
|
||||||
[this._loadHtml(viewDef.template, viewDef.templateAbsUrl)];
|
[this._loadHtml(viewDef.template, viewDef.templateAbsUrl, viewDef.componentId)];
|
||||||
if (isPresent(viewDef.styles)) {
|
if (isPresent(viewDef.styles)) {
|
||||||
viewDef.styles.forEach((cssText: string) => {
|
viewDef.styles.forEach((cssText: string) => {
|
||||||
let textOrPromise = this._resolveAndInlineCssText(cssText, viewDef.templateAbsUrl);
|
let textOrPromise = this._resolveAndInlineCssText(cssText, viewDef.templateAbsUrl);
|
||||||
|
@ -83,7 +83,8 @@ export class ViewLoader {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load the html and inline any style tags
|
// Load the html and inline any style tags
|
||||||
private _loadHtml(template: string, templateAbsUrl: string): Promise<TemplateAndStyles> {
|
private _loadHtml(template: string, templateAbsUrl: string,
|
||||||
|
componentId: string): Promise<TemplateAndStyles> {
|
||||||
let html;
|
let html;
|
||||||
|
|
||||||
// Load the HTML
|
// Load the HTML
|
||||||
|
@ -92,7 +93,8 @@ export class ViewLoader {
|
||||||
} else if (isPresent(templateAbsUrl)) {
|
} else if (isPresent(templateAbsUrl)) {
|
||||||
html = this._loadText(templateAbsUrl);
|
html = this._loadText(templateAbsUrl);
|
||||||
} else {
|
} else {
|
||||||
throw new BaseException('View should have either the templateUrl or template property set');
|
throw new BaseException(
|
||||||
|
`View should have either the templateUrl or template property set but none was found for the '${componentId}' component`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return html.then(html => {
|
return html.then(html => {
|
||||||
|
|
|
@ -83,8 +83,10 @@ export function main() {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should throw when no template is defined', () => {
|
it('should throw when no template is defined', () => {
|
||||||
expect(() => loader.load(new ViewDefinition({template: null, templateAbsUrl: null})))
|
expect(() => loader.load(new ViewDefinition(
|
||||||
.toThrowError('View should have either the templateUrl or template property set');
|
{componentId: 'TestComponent', template: null, templateAbsUrl: null})))
|
||||||
|
.toThrowError(
|
||||||
|
'View should have either the templateUrl or template property set but none was found for the \'TestComponent\' component');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return a rejected Promise when XHR loading fails',
|
it('should return a rejected Promise when XHR loading fails',
|
||||||
|
|
Loading…
Reference in New Issue