mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-24 19:32:07 +00:00
Add test for readme parsing
This commit is contained in:
@@ -12,6 +12,14 @@ Readme.prototype.getFile = function() {
|
||||
return this.get('file');
|
||||
};
|
||||
|
||||
Readme.prototype.getTitle = function() {
|
||||
return this.get('title');
|
||||
};
|
||||
|
||||
Readme.prototype.getDescription = function() {
|
||||
return this.get('description');
|
||||
};
|
||||
|
||||
/**
|
||||
Create a new readme
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
jest.autoMockOff();
|
||||
|
||||
var Promise = require('../../utils/promise');
|
||||
var Book = require('../../models/book');
|
||||
var createMockFS = require('../../fs/mock');
|
||||
|
||||
describe('parseReadme', function() {
|
||||
var parseReadme = require('../parseReadme');
|
||||
|
||||
pit('should parse summary if exists', function() {
|
||||
var fs = createMockFS({
|
||||
'README.md': '# Hello\n\nAnd here is the description.'
|
||||
});
|
||||
var book = Book.createForFS(fs);
|
||||
|
||||
return parseReadme(book)
|
||||
.then(function(resultBook) {
|
||||
var readme = resultBook.getReadme();
|
||||
var file = readme.getFile();
|
||||
|
||||
expect(file.exists()).toBeTruthy();
|
||||
expect(readme.getTitle()).toBe('Hello');
|
||||
expect(readme.getDescription()).toBe('And here is the description.');
|
||||
});
|
||||
});
|
||||
|
||||
pit('should fail if doesn\'t exist', function() {
|
||||
var fs = createMockFS({});
|
||||
var book = Book.createForFS(fs);
|
||||
|
||||
return parseReadme(book)
|
||||
.then(function(resultBook) {
|
||||
throw new Error('It should have fail');
|
||||
}, function() {
|
||||
return Promise();
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user