parent
3f331b53b2
commit
99b666614d
|
@ -31,8 +31,14 @@ describe('example inline-tag-def', function() {
|
|||
};
|
||||
});
|
||||
|
||||
it('should return a <code-example> tag', () => {
|
||||
expect(handler({}, 'example', 'some/uri')).toEqual('<code-example>\n\n</code-example>');
|
||||
it('should throw an error if there is no matching example', () => {
|
||||
expect(function() {
|
||||
handler({}, 'example', 'missing/uri');
|
||||
}).toThrowError();
|
||||
|
||||
expect(function() {
|
||||
handler({}, 'example', 'test/url missing-region');
|
||||
}).toThrowError();
|
||||
});
|
||||
|
||||
it('should contain the whole contents from the example file if no region is specified', () => {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
module.exports = function getExampleRegion(exampleMap, createDocMessage, log, collectExamples) {
|
||||
module.exports = function getExampleRegion(exampleMap, createDocMessage, collectExamples) {
|
||||
return function getExampleRegionImpl(doc, relativePath, regionName) {
|
||||
const EXAMPLES_FOLDERS = collectExamples.exampleFolders;
|
||||
|
||||
|
@ -14,16 +14,16 @@ module.exports = function getExampleRegion(exampleMap, createDocMessage, log, co
|
|||
|
||||
// If still no file then we error
|
||||
if (!exampleFile) {
|
||||
log.error(createDocMessage('Missing example file... relativePath: "' + relativePath + '".', doc));
|
||||
log.error('Example files can be found in: ' + EXAMPLES_FOLDERS.join(', '));
|
||||
return '';
|
||||
const message = createDocMessage('Missing example file... relativePath: "' + relativePath + '".', doc) + '\n' +
|
||||
'Example files can be found in: ' + EXAMPLES_FOLDERS.join(', ');
|
||||
throw new Error(message);
|
||||
}
|
||||
|
||||
var sourceCodeDoc = exampleFile.regions[regionName || ''];
|
||||
if (!sourceCodeDoc) {
|
||||
log.error(createDocMessage('Missing example region... relativePath: "' + relativePath + '", region: "' + regionName + '".', doc));
|
||||
log.error('Regions available are:', Object.keys[exampleFile.regions]);
|
||||
return '';
|
||||
const message = createDocMessage('Missing example region... relativePath: "' + relativePath + '", region: "' + regionName + '".', doc) + '\n' +
|
||||
'Regions available are:' + Object.keys[exampleFile.regions];
|
||||
throw new Error(message);
|
||||
}
|
||||
|
||||
return sourceCodeDoc.renderedContent;
|
||||
|
|
|
@ -26,4 +26,13 @@ describe('getExampleRegion', () => {
|
|||
it('should contain the region contents from the example file if a region is specified', () => {
|
||||
expect(getExampleRegion({}, 'test/url', 'region-1')).toEqual('region 1 contents');
|
||||
});
|
||||
|
||||
it('should throw an error if an example doesn\'t exist', function() {
|
||||
expect(function() {
|
||||
getExampleRegion({}, 'missing/file', 'region-1');
|
||||
}).toThrowError();
|
||||
expect(function() {
|
||||
getExampleRegion({}, 'test/url', 'missing-region');
|
||||
}).toThrowError();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue