Fix error when summary contains entry without ref

This commit is contained in:
Samy Pessé
2016-05-10 12:12:19 +02:00
parent 5b3f54fbc8
commit d342d31c8e
2 changed files with 22 additions and 4 deletions
+16 -3
View File
@@ -8,11 +8,18 @@ describe('Summary', function() {
articles: [
{
title: 'My First Article',
path: 'README.md'
ref: 'README.md'
},
{
title: 'My Second Article',
path: 'article.md'
ref: 'article.md'
},
{
title: 'Article without ref'
},
{
title: 'Article with absolute ref',
ref: 'https://google.fr'
}
]
},
@@ -33,7 +40,7 @@ describe('Summary', function() {
var part = summary.getByLevel('1');
expect(part).toBeDefined();
expect(part.getArticles().size).toBe(2);
expect(part.getArticles().size).toBe(4);
});
it('can return a Part (2)', function() {
@@ -66,6 +73,12 @@ describe('Summary', function() {
expect(article).toBeDefined();
expect(article.getTitle()).toBe('My Second Article');
});
it('return undefined if not found', function() {
var article = summary.getByPath('NOT_EXISTING.md');
expect(article).toBeFalsy();
});
});
describe('toText', function() {
+6 -1
View File
@@ -74,7 +74,12 @@ Summary.prototype.getByLevel = function(level) {
*/
Summary.prototype.getByPath = function(filePath) {
return this.getArticle(function(article) {
return (LocationUtils.areIdenticalPaths(article.getPath(), filePath));
var articlePath = article.getPath();
return (
articlePath &&
LocationUtils.areIdenticalPaths(articlePath, filePath)
);
});
};