Improve error-message when partial is missing

Signed-off-by: Seyed Mohammad Mahdi Hatami <hatamik7@gmail.com>
This commit is contained in:
Seyed Mohammad Mahdi Hatami
2023-06-29 00:54:40 +03:30
committed by Jay Linski
parent d3b93571a7
commit 8ce2be4496
2 changed files with 10 additions and 5 deletions
+3 -1
View File
@@ -376,7 +376,9 @@ export function invokePartial(partial, context, options) {
} }
if (partial === undefined) { if (partial === undefined) {
throw new Exception('The partial ' + options.name + ' could not be found'); throw new Exception(
'The partial "' + options.name + '" could not be found'
);
} else if (partial instanceof Function) { } else if (partial instanceof Function) {
return partial(context, options); return partial(context, options);
} }
+7 -4
View File
@@ -64,7 +64,10 @@ describe('partials', function () {
return 'missing'; return 'missing';
}) })
.withPartial('dude', '{{name}} ({{url}}) ') .withPartial('dude', '{{name}} ({{url}}) ')
.toThrow(Handlebars.Exception, 'The partial missing could not be found'); .toThrow(
Handlebars.Exception,
'The partial "missing" could not be found'
);
}); });
it('partials with context', function () { it('partials with context', function () {
@@ -156,7 +159,7 @@ describe('partials', function () {
it('rendering undefined partial throws an exception', function () { it('rendering undefined partial throws an exception', function () {
expectTemplate('{{> whatever}}').toThrow( expectTemplate('{{> whatever}}').toThrow(
Handlebars.Exception, Handlebars.Exception,
'The partial whatever could not be found' 'The partial "whatever" could not be found'
); );
}); });
@@ -174,7 +177,7 @@ describe('partials', function () {
it('rendering template partial in vm mode throws an exception', function () { it('rendering template partial in vm mode throws an exception', function () {
expectTemplate('{{> whatever}}').toThrow( expectTemplate('{{> whatever}}').toThrow(
Handlebars.Exception, Handlebars.Exception,
'The partial whatever could not be found' 'The partial "whatever" could not be found'
); );
}); });
@@ -472,7 +475,7 @@ describe('partials', function () {
expectTemplate( expectTemplate(
'{{#with .}}{{#*inline "myPartial"}}success{{/inline}}{{/with}}{{> myPartial}}' '{{#with .}}{{#*inline "myPartial"}}success{{/inline}}{{/with}}{{> myPartial}}'
).toThrow(Error, /myPartial could not/); ).toThrow(Error, /"myPartial" could not/);
}); });
it('should override global partials', function () { it('should override global partials', function () {